msdf/MSDF-Test/Texture.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2024-05-12 22:51:23 +02:00
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
2024-05-12 22:35:52 +02:00
namespace MSDF_Test;
2024-05-12 22:51:23 +02:00
[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
internal readonly struct Texture
2024-05-12 22:35:52 +02:00
{
2024-05-12 22:51:23 +02:00
private readonly Bitmap _image;
private readonly int _glyphSize;
private readonly int _padding;
2024-05-12 22:35:52 +02:00
2024-05-12 22:51:23 +02:00
internal Texture(Bitmap image, int glyphSize, int padding)
2024-05-12 22:35:52 +02:00
{
2024-05-12 22:51:23 +02:00
this._image = image;
this._glyphSize = glyphSize;
this._padding = padding;
2024-05-12 22:35:52 +02:00
}
internal List<Bitmap> GetGlyphBitmaps()
{
List<Bitmap> ret = new();
2024-05-12 22:51:23 +02:00
for (int y = _padding; y < _image.Width - _padding; y += _glyphSize + _padding)
2024-05-12 22:35:52 +02:00
{
2024-05-12 22:51:23 +02:00
for (int x = _padding; x < _image.Height - _padding; x += _glyphSize + _padding)
2024-05-12 22:35:52 +02:00
{
Point topLeft = new (x, y);
2024-05-12 22:51:23 +02:00
ret.Add(_image.Clone(new Rectangle(topLeft, new Size(_glyphSize, _glyphSize)), _image.PixelFormat));
2024-05-12 22:35:52 +02:00
}
}
return ret;
}
2024-05-12 22:51:23 +02:00
public Texture(string imagePath, int glyphSize, int padding) : this((Bitmap)Image.FromFile(imagePath), glyphSize, padding)
2024-05-12 22:35:52 +02:00
{
}
}