diff --git a/PCK-Studio/Classes/Extentions/ImageExtentions.cs b/PCK-Studio/Classes/Extentions/ImageExtentions.cs index 4234ef07..640d9fca 100644 --- a/PCK-Studio/Classes/Extentions/ImageExtentions.cs +++ b/PCK-Studio/Classes/Extentions/ImageExtentions.cs @@ -7,6 +7,12 @@ namespace PckStudio.Classes.Extentions { internal static class ImageExtentions { + public enum ImageLayoutDirection + { + Horizontal, + Vertical + } + public static IEnumerable 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 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; + } + } } diff --git a/PCK-Studio/Forms/Editor/AnimationEditor.cs b/PCK-Studio/Forms/Editor/AnimationEditor.cs index e68e4f90..4468fb99 100644 --- a/PCK-Studio/Forms/Editor/AnimationEditor.cs +++ b/PCK-Studio/Forms/Editor/AnimationEditor.cs @@ -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(SplitImageToFrameTextures(image)); + frameTextures = new List(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 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 GetFrames()