Created ImageUtils to hold CreateImageList

This commit is contained in:
MattNL
2023-03-02 21:55:57 -05:00
parent b6b4a1aad9
commit e2153924d7

View File

@@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Diagnostics;
namespace PckStudio.Classes.Utils
{
internal class ImageUtils
{
public static IEnumerable<Image> CreateImageList(Image source, int size)
{
int img_row_count = source.Width / size;
int img_column_count = source.Height / size;
Debug.WriteLine($"{source.Width} {source.Height} {size} {size} {img_column_count} {img_row_count}");
for (int i = 0; i < img_column_count * img_row_count; i++)
{
int row = i / img_row_count;
int column = i % img_row_count;
Rectangle tileArea = new Rectangle(new Point(column * size, row * size), new Size(size, size));
Bitmap tileImage = new Bitmap(size, size);
using (Graphics gfx = Graphics.FromImage(tileImage))
{
gfx.SmoothingMode = SmoothingMode.None;
gfx.InterpolationMode = InterpolationMode.NearestNeighbor;
gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
gfx.DrawImage(source, new Rectangle(0, 0, size, size), tileArea, GraphicsUnit.Pixel);
}
yield return tileImage;
}
yield break;
}
}
}