ResizeWithRatio

This commit is contained in:
iAmAsval
2021-09-10 23:39:49 +02:00
parent a741131a37
commit 4824aa01aa
5 changed files with 13 additions and 5 deletions

View File

@@ -38,7 +38,9 @@ namespace FModel.Creator.Bases.FN
!_apiEndpointView.FortniteApi.TryGetBytes(playlist.Data.Images.Showcase, out var image))
return;
Preview = Utils.GetBitmap(image).Resize(1024, 512); // Force size to 1024x512 to prevent huge previews.
Preview = Utils.GetBitmap(image).ResizeWithRatio(1024, 512);
Width = Preview.Width;
Height = Preview.Height;
}
public override SKImage Draw()

View File

@@ -108,7 +108,6 @@ namespace FModel.Creator
public static SKBitmap GetBitmap(byte[] data) => SKBitmap.Decode(data);
public static SKBitmap Resize(this SKBitmap me, int size) => me.Resize(size, size);
public static SKBitmap Resize(this SKBitmap me, int width, int height)
{
var bmp = new SKBitmap(new SKImageInfo(width, height), SKBitmapAllocFlags.ZeroPixels);
@@ -116,6 +115,13 @@ namespace FModel.Creator
me.ScalePixels(pixmap, SKFilterQuality.Medium);
return bmp;
}
public static SKBitmap ResizeWithRatio(this SKBitmap me, double width, double height)
{
var ratioX = width / me.Width;
var ratioY = height / me.Height;
var ratio = ratioX < ratioY ? ratioX : ratioY;
return me.Resize(Convert.ToInt32(me.Width * ratio), Convert.ToInt32(me.Height * ratio));
}
public static bool TryGetPackageIndexExport<T>(FPackageIndex packageIndex, out T export) where T : UObject
{

View File

@@ -535,4 +535,4 @@ namespace FModel.Settings
set => SetProperty(ref _textureExportFormat, value);
}
}
}
}

View File

@@ -183,4 +183,4 @@ namespace FModel.ViewModels
}
#pragma warning restore 649
}
}
}