diff options
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs')
-rw-r--r-- | Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs b/Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs new file mode 100644 index 00000000..edf7dc37 --- /dev/null +++ b/Xamarin.Forms.Platform.Android/Renderers/FileImageSourceHandler.cs @@ -0,0 +1,17 @@ +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using Android.Content; +using Android.Graphics; + +namespace Xamarin.Forms.Platform.Android +{ + public sealed class FileImageSourceHandler : IImageSourceHandler + { + public async Task<Bitmap> LoadImageAsync(ImageSource imagesource, Context context, CancellationToken cancelationToken = default(CancellationToken)) + { + string file = ((FileImageSource)imagesource).File; + return await (File.Exists(file) ? BitmapFactory.DecodeFileAsync(file) : context.Resources.GetBitmapAsync(file)).ConfigureAwait(false); + } + } +}
\ No newline at end of file |