mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-07-16 00:28:25 +00:00
ImageExtentions - Add another overload for CreateImageList that accepts an ImageLayoutDirection
This commit is contained in:
@@ -7,6 +7,12 @@ namespace PckStudio.Classes.Extentions
|
||||
{
|
||||
internal static class ImageExtentions
|
||||
{
|
||||
public enum ImageLayoutDirection
|
||||
{
|
||||
Horizontal,
|
||||
Vertical
|
||||
}
|
||||
|
||||
public static IEnumerable<Image> CreateImageList(this Image source, Size size)
|
||||
{
|
||||
int img_row_count = source.Width / size.Width;
|
||||
@@ -36,5 +42,27 @@ namespace PckStudio.Classes.Extentions
|
||||
{
|
||||
return CreateImageList(source, new Size(scalar, scalar));
|
||||
}
|
||||
|
||||
public static IEnumerable<Image> CreateImageList(this Image source, ImageLayoutDirection layoutDirection)
|
||||
{
|
||||
for (int i = 0; i < source.Height / source.Width; i++)
|
||||
{
|
||||
(Size size, Point point) locationInfo = layoutDirection == ImageLayoutDirection.Horizontal
|
||||
? (new Size(source.Width, source.Width), new Point(0, i * source.Width))
|
||||
: (new Size(source.Height, source.Height), new Point(i * source.Height, 0));
|
||||
Rectangle tileArea = new Rectangle(locationInfo.point, locationInfo.size);
|
||||
Bitmap tileImage = new Bitmap(locationInfo.size.Width, locationInfo.size.Height);
|
||||
using (Graphics gfx = Graphics.FromImage(tileImage))
|
||||
{
|
||||
gfx.SmoothingMode = SmoothingMode.None;
|
||||
gfx.InterpolationMode = InterpolationMode.NearestNeighbor;
|
||||
gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
gfx.DrawImage(source, new Rectangle(Point.Empty, locationInfo.size), tileArea, GraphicsUnit.Pixel);
|
||||
}
|
||||
yield return tileImage;
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ using System.Windows.Forms;
|
||||
using PckStudio.Classes.FileTypes;
|
||||
using PckStudio.Forms.Additional_Popups.Animation;
|
||||
using PckStudio.Forms.Utilities;
|
||||
using PckStudio.Classes.Extentions;
|
||||
|
||||
namespace PckStudio.Forms.Editor
|
||||
{
|
||||
@@ -43,7 +44,7 @@ namespace PckStudio.Forms.Editor
|
||||
|
||||
public Animation(Image image)
|
||||
{
|
||||
frameTextures = new List<Image>(SplitImageToFrameTextures(image));
|
||||
frameTextures = new List<Image>(image.CreateImageList(ImageExtentions.ImageLayoutDirection.Horizontal));
|
||||
}
|
||||
|
||||
public Animation(Image image, string ANIM) : this(image)
|
||||
@@ -117,24 +118,6 @@ namespace PckStudio.Forms.Editor
|
||||
return true;
|
||||
}
|
||||
|
||||
private static IEnumerable<Image> SplitImageToFrameTextures(Image source)
|
||||
{
|
||||
for (int i = 0; i < source.Height / source.Width; i++)
|
||||
{
|
||||
Rectangle tileArea = new Rectangle(0, i * source.Width, source.Width, source.Width);
|
||||
Bitmap tileImage = new Bitmap(source.Width, source.Width);
|
||||
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, source.Width, source.Width), tileArea, GraphicsUnit.Pixel);
|
||||
}
|
||||
yield return tileImage;
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
|
||||
public Frame GetFrame(int index) => frames[index];
|
||||
|
||||
public List<Frame> GetFrames()
|
||||
|
||||
Reference in New Issue
Block a user