From 7cb31c526e436072a73c8bae663f7e32f0139436 Mon Sep 17 00:00:00 2001
From: miku-666 <74728189+NessieHax@users.noreply.github.com>
Date: Fri, 16 Jan 2026 15:37:30 +0100
Subject: [PATCH] Core(ImgExt) - Add overload for scale size
---
PckStudio.Core/Extensions/ImageExtensions.cs | 18 ++++++++++++++++--
PckStudio.Core/PckStudio.Core.csproj | 2 +-
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/PckStudio.Core/Extensions/ImageExtensions.cs b/PckStudio.Core/Extensions/ImageExtensions.cs
index 4109fdf7..8c4ab559 100644
--- a/PckStudio.Core/Extensions/ImageExtensions.cs
+++ b/PckStudio.Core/Extensions/ImageExtensions.cs
@@ -42,17 +42,31 @@ namespace PckStudio.Core.Extensions
public static Color GetColor(this Image image, Point location) => image.GetColor(location.X, location.Y);
public static Color GetColor(this Image image, int x, int y) => new Bitmap(image).GetPixel(x, y);
+ public static Image GetArea(this Image source, int x, int y, int width, int height, Size scale)
+ => source.GetArea(new Point(x,y), new Size(width, height), scale);
+
public static Image GetArea(this Image source, int x, int y, int width, int height)
=> source.GetArea(new Point(x, y), new Size(width, height));
+
public static Image GetArea(this Image source, Point location, Size size)
=> source.GetArea(new Rectangle(location, size));
+
+ public static Image GetArea(this Image source, Point location, Size size, Size scale)
+ => source.GetArea(new Rectangle(location, size), scale);
+
public static Image GetArea(this Image source, Rectangle area)
+ => source.GetArea(area, new Size(1,1));
+ public static Image GetArea(this Image source, Rectangle area, Size scale)
{
- Image result = new Bitmap(area.Width, area.Height);
+ Point srcLocation = new Point(area.X * scale.Width, area.Y * scale.Height);
+ Size srcSize = new Size(area.Width * scale.Width, area.Height * scale.Height);
+ Rectangle srcRect = new Rectangle(srcLocation, srcSize);
+
+ Image result = new Bitmap(srcSize.Width, srcSize.Height);
using (Graphics gfx = Graphics.FromImage(result))
{
gfx.ApplyConfig(GraphicsConfig.PixelPerfect());
- gfx.DrawImage(source, new Rectangle(Point.Empty, area.Size), area, GraphicsUnit.Pixel);
+ gfx.DrawImage(source, new Rectangle(Point.Empty, result.Size), srcRect, GraphicsUnit.Pixel);
}
return result;
}
diff --git a/PckStudio.Core/PckStudio.Core.csproj b/PckStudio.Core/PckStudio.Core.csproj
index 8461a45b..7151872a 100644
--- a/PckStudio.Core/PckStudio.Core.csproj
+++ b/PckStudio.Core/PckStudio.Core.csproj
@@ -57,7 +57,7 @@
-
+