Improve ImageLoader performance

This commit is contained in:
Jack251970 2025-09-18 18:29:45 +08:00
parent e50a2772f8
commit fc2e3fec63

View file

@ -22,7 +22,7 @@ namespace Flow.Launcher.Infrastructure.Image
private static Lock storageLock { get; } = new(); private static Lock storageLock { get; } = new();
private static BinaryStorage<List<(string, bool)>> _storage; private static BinaryStorage<List<(string, bool)>> _storage;
private static readonly ConcurrentDictionary<string, string> GuidToKey = new(); private static readonly ConcurrentDictionary<string, string> GuidToKey = new();
private static IImageHashGenerator _hashGenerator; private static ImageHashGenerator _hashGenerator;
private static readonly bool EnableImageHash = true; private static readonly bool EnableImageHash = true;
public static ImageSource Image => ImageCache[Constant.ImageIcon, false]; public static ImageSource Image => ImageCache[Constant.ImageIcon, false];
public static ImageSource MissingImage => ImageCache[Constant.MissingImgIcon, false]; public static ImageSource MissingImage => ImageCache[Constant.MissingImgIcon, false];
@ -31,7 +31,7 @@ namespace Flow.Launcher.Infrastructure.Image
public const int FullIconSize = 256; public const int FullIconSize = 256;
public const int FullImageSize = 320; public const int FullImageSize = 320;
private static readonly string[] ImageExtensions = { ".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".ico" }; private static readonly string[] ImageExtensions = [".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".ico"];
private static readonly string SvgExtension = ".svg"; private static readonly string SvgExtension = ".svg";
public static async Task InitializeAsync() public static async Task InitializeAsync()
@ -327,7 +327,7 @@ namespace Flow.Launcher.Infrastructure.Image
return img; return img;
} }
private static ImageSource LoadFullImage(string path) private static BitmapImage LoadFullImage(string path)
{ {
BitmapImage image = new BitmapImage(); BitmapImage image = new BitmapImage();
image.BeginInit(); image.BeginInit();
@ -364,7 +364,7 @@ namespace Flow.Launcher.Infrastructure.Image
return image; return image;
} }
private static ImageSource LoadSvgImage(string path, bool loadFullImage = false) private static RenderTargetBitmap LoadSvgImage(string path, bool loadFullImage = false)
{ {
// Set up drawing settings // Set up drawing settings
var desiredHeight = loadFullImage ? FullImageSize : SmallIconSize; var desiredHeight = loadFullImage ? FullImageSize : SmallIconSize;