From 402f80e6a4a0a4d0c6fc9a1d69edbea282cdb124 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Wed, 27 Oct 2021 17:03:49 -0600 Subject: [PATCH] Further optimize the gallery --- Wabbajack.App/Controls/BrowseItemView.axaml | 6 +----- Wabbajack.App/Controls/BrowseItemViewModel.cs | 2 +- Wabbajack.App/Models/ImageCache.cs | 10 ++++++---- Wabbajack.App/Wabbajack.App.csproj | 4 ++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Wabbajack.App/Controls/BrowseItemView.axaml b/Wabbajack.App/Controls/BrowseItemView.axaml index 1d58bfcd..6b6850d5 100644 --- a/Wabbajack.App/Controls/BrowseItemView.axaml +++ b/Wabbajack.App/Controls/BrowseItemView.axaml @@ -10,11 +10,7 @@ - - - - + diff --git a/Wabbajack.App/Controls/BrowseItemViewModel.cs b/Wabbajack.App/Controls/BrowseItemViewModel.cs index bf05346f..5e0b7d05 100644 --- a/Wabbajack.App/Controls/BrowseItemViewModel.cs +++ b/Wabbajack.App/Controls/BrowseItemViewModel.cs @@ -167,7 +167,7 @@ public class BrowseItemViewModel : ViewModelBase, IActivatableViewModel public async Task LoadListImage() { - Image = await _imageCache.From(ImageUri); + Image = await _imageCache.From(ImageUri, 540, 300); } public async Task GetState() diff --git a/Wabbajack.App/Models/ImageCache.cs b/Wabbajack.App/Models/ImageCache.cs index ac11adc3..927a9882 100644 --- a/Wabbajack.App/Models/ImageCache.cs +++ b/Wabbajack.App/Models/ImageCache.cs @@ -28,16 +28,18 @@ public class ImageCache _limiter = limiter; } - public async Task From(Uri uri) + public async Task From(Uri uri, int width, int height) { var hash = (await Encoding.UTF8.GetBytes(uri.ToString()).Hash()).ToHex(); - var file = _configuration.ImageCacheLocation.Combine(hash); + var file = _configuration.ImageCacheLocation.Combine(hash + $"_{width}_{height}"); + if (!file.FileExists()) { using var job = await _limiter.Begin("Loading Image", 0, CancellationToken.None); + var wdata = await _client.GetByteArrayAsync(uri); - await file.WriteAllBytesAsync(wdata); - return new Bitmap(new MemoryStream(wdata)); + var resized = SKBitmap.Decode(wdata).Resize(new SKSizeI(width, height), SKFilterQuality.High); + await file.WriteAllBytesAsync(resized.Encode(SKEncodedImageFormat.Webp, 90).ToArray()); } var data = await file.ReadAllBytesAsync(); diff --git a/Wabbajack.App/Wabbajack.App.csproj b/Wabbajack.App/Wabbajack.App.csproj index e7b71c8c..9d156d96 100644 --- a/Wabbajack.App/Wabbajack.App.csproj +++ b/Wabbajack.App/Wabbajack.App.csproj @@ -1,4 +1,4 @@ - + Exe net6.0-windows @@ -50,7 +50,7 @@ - +