mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-17 16:01:53 +00:00
Created ImageUtils to hold CreateImageList
This commit is contained in:
34
PCK-Studio/Classes/Utils/ImageUtils.cs
Normal file
34
PCK-Studio/Classes/Utils/ImageUtils.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user