From 72a7a60cd8ca99314b01b56fae38122f92d9029e Mon Sep 17 00:00:00 2001 From: MayNL Date: Mon, 11 May 2026 19:01:26 -0400 Subject: [PATCH] Fix crash for replacing tile group with smaller images -The selected image is now stretched to fit the size of the tile group to show the user how the new image is applied --- PckStudio.Core/Atlas.cs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/PckStudio.Core/Atlas.cs b/PckStudio.Core/Atlas.cs index d30f19b0..cd331785 100644 --- a/PckStudio.Core/Atlas.cs +++ b/PckStudio.Core/Atlas.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Drawing.Drawing2D; using System.Linq; using PckStudio.Core.Extensions; @@ -221,11 +222,27 @@ namespace PckStudio.Core public void SetGroup(AtlasGroup group, Image texture) { - IEnumerable images = texture.Split(TileSize, group.Direction); - if (!images.All(img => img.Size == TileSize)) - return; - Size s = group.GetSize(new Size(1, 1)); - SetRange(group.Row, group.Column, s.Width, s.Height, images); + Size tileSize = group.GetSize(new Size(1, 1)); + + // stretch image too small or too big to fit space + Size targetSize = new Size( + tileSize.Width * TileSize.Width, + tileSize.Height * TileSize.Height); + + Bitmap finalGroup = new Bitmap(targetSize.Width, targetSize.Height); + + using (Graphics gfx = Graphics.FromImage(finalGroup)) + { + gfx.InterpolationMode = InterpolationMode.NearestNeighbor; + gfx.PixelOffsetMode = PixelOffsetMode.Half; + gfx.CompositingQuality = CompositingQuality.HighSpeed; + + gfx.DrawImage(texture, 0, 0, targetSize.Width, targetSize.Height); + } + + IEnumerable images = finalGroup.Split(TileSize, group.Direction); + + SetRange(group.Row, group.Column, tileSize.Width, tileSize.Height, images); } } } \ No newline at end of file