mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-09-24 18:50:47 +00:00
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
This commit is contained in:
+22
-5
@@ -18,6 +18,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using PckStudio.Core.Extensions;
|
using PckStudio.Core.Extensions;
|
||||||
|
|
||||||
@@ -221,11 +222,27 @@ namespace PckStudio.Core
|
|||||||
|
|
||||||
public void SetGroup(AtlasGroup group, Image texture)
|
public void SetGroup(AtlasGroup group, Image texture)
|
||||||
{
|
{
|
||||||
IEnumerable<Image> images = texture.Split(TileSize, group.Direction);
|
Size tileSize = group.GetSize(new Size(1, 1));
|
||||||
if (!images.All(img => img.Size == TileSize))
|
|
||||||
return;
|
// stretch image too small or too big to fit space
|
||||||
Size s = group.GetSize(new Size(1, 1));
|
Size targetSize = new Size(
|
||||||
SetRange(group.Row, group.Column, s.Width, s.Height, images);
|
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<Image> images = finalGroup.Split(TileSize, group.Direction);
|
||||||
|
|
||||||
|
SetRange(group.Row, group.Column, tileSize.Width, tileSize.Height, images);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user