Skip to content

Commit

Permalink
load error icon using cache
Browse files Browse the repository at this point in the history
  • Loading branch information
bao-qian committed May 15, 2020
1 parent c5e3115 commit b340d7e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Wox/Image/ImageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ private static ImageSource LoadInternal(string path)
bool imageInsideWoxDirectory = IsSubdirectory(parent1, subPath) || IsSubdirectory(parent2, subPath);
if (normalImage && imageInsideWoxDirectory)
{
var bitmapImage = new BitmapImage(new Uri(path))
image = new BitmapImage(new Uri(path))
{
DecodePixelHeight = 32,
DecodePixelWidth = 32
};
image = bitmapImage;
image.Freeze();
return image;
}
Expand Down Expand Up @@ -159,10 +158,16 @@ private static ImageSource LoadInternal(string path)

private static ImageSource GetErrorImage()
{
ShellFile shellFile = ShellFile.FromFilePath(Constant.ErrorIcon);
// small is (32, 32), refer comment above
ImageSource image = shellFile.Thumbnail.SmallBitmapSource;
image.Freeze();
ImageSource image = _cache.GetOrAdd(Constant.ErrorIcon, (_) =>
{
BitmapImage bitmap = new BitmapImage(new Uri(Constant.ErrorIcon))
{
DecodePixelHeight = 32,
DecodePixelWidth = 32
};
bitmap.Freeze();
return bitmap;
});
return image;
}

Expand Down

0 comments on commit b340d7e

Please sign in to comment.