Fix ImageResize to accept width 0 or height = 0

This commit is contained in:
TheXamlGuy
2024-10-10 12:20:56 +01:00
parent b0f53ff420
commit 1e402960f3
+11
View File
@@ -18,6 +18,16 @@ public class ImageResizer :
stream.Seek(0, SeekOrigin.Begin);
using SKBitmap sKBitmap = SKBitmap.Decode(stream);
if (targetHeight == 0 && maintainAspectRatio)
{
targetHeight = (int)((float)targetWidth / sKBitmap.Width * sKBitmap.Height);
}
if (targetWidth == 0 && maintainAspectRatio)
{
targetWidth = (int)((float)targetHeight / sKBitmap.Height * sKBitmap.Width);
}
float widthRatio = (float)targetWidth / sKBitmap.Width;
float heightRatio = (float)targetHeight / sKBitmap.Height;
float scale = maintainAspectRatio ? Math.Max(widthRatio, heightRatio) : Math.Min(widthRatio, heightRatio);
@@ -65,4 +75,5 @@ public class ImageResizer :
return bitmap;
}
}