diff --git a/StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs b/StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs index 095ea2ce..89951a9a 100644 --- a/StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs +++ b/StabilityMatrix.Avalonia/Helpers/PngDataHelper.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Text; using System.Text.Json; +using Avalonia; using Force.Crc32; using StabilityMatrix.Avalonia.Models; using StabilityMatrix.Core.Models; @@ -84,6 +85,32 @@ public static class PngDataHelper return finalImage.ToArray(); } + public static Size GetImageSize(byte[] inputImage) + { + var imageWidthBytes = inputImage[0x10..0x14]; + var imageHeightBytes = inputImage[0x14..0x18]; + var imageWidth = BitConverter.ToInt32(imageWidthBytes.Reverse().ToArray()); + var imageHeight = BitConverter.ToInt32(imageHeightBytes.Reverse().ToArray()); + + return new Size(imageWidth, imageHeight); + } + + public static Size GetImageSize(BinaryReader reader) + { + var oldPosition = reader.BaseStream.Position; + + reader.BaseStream.Position = 0x10; + var imageWidthBytes = reader.ReadBytes(4); + var imageHeightBytes = reader.ReadBytes(4); + + var imageWidth = BitConverter.ToInt32(imageWidthBytes.Reverse().ToArray()); + var imageHeight = BitConverter.ToInt32(imageHeightBytes.Reverse().ToArray()); + + reader.BaseStream.Position = oldPosition; + + return new Size(imageWidth, imageHeight); + } + private static byte[] BuildTextChunk(string key, string value) { var textData = $"{key}\0{value}";