From 2e30a2034946f3b3f22bbd6c81b421daf8d7afc4 Mon Sep 17 00:00:00 2001 From: afunc Date: Sat, 27 May 2023 16:18:38 +0800 Subject: [PATCH] LoadFromLocalAsync --- .../Loaders/BaseWebImageLoader.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/AsyncImageLoader.Avalonia/Loaders/BaseWebImageLoader.cs b/AsyncImageLoader.Avalonia/Loaders/BaseWebImageLoader.cs index 8198445..86df9e6 100644 --- a/AsyncImageLoader.Avalonia/Loaders/BaseWebImageLoader.cs +++ b/AsyncImageLoader.Avalonia/Loaders/BaseWebImageLoader.cs @@ -62,7 +62,8 @@ public void Dispose() /// Bitmap protected virtual async Task LoadAsync(string url) { - var internalOrCachedBitmap = await LoadFromInternalAsync(url) ?? await LoadFromGlobalCache(url); + var internalOrCachedBitmap = await LoadFromLocalAsync(url) ?? + await LoadFromInternalAsync(url) ?? await LoadFromGlobalCache(url); if (internalOrCachedBitmap != null) return internalOrCachedBitmap; try @@ -81,6 +82,16 @@ public void Dispose() } } + /// + /// the url maybe is local file url,so if file exists ,we got a Bitmap + /// + /// + /// + private Task LoadFromLocalAsync(string url) + { + return Task.FromResult(File.Exists(url) ? new Bitmap(url) : null); + } + /// /// Receives image bytes from an internal source (for example, from the disk). /// This data will be NOT cached globally (because it is assumed that it is already in internal source us and does not