summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Renderers/ImageLoaderSourceHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Renderers/ImageLoaderSourceHandler.cs')
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/ImageLoaderSourceHandler.cs22
1 files changed, 22 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/ImageLoaderSourceHandler.cs b/Xamarin.Forms.Platform.Android/Renderers/ImageLoaderSourceHandler.cs
new file mode 100644
index 00000000..541dbeaf
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/Renderers/ImageLoaderSourceHandler.cs
@@ -0,0 +1,22 @@
+using System.IO;
+using System.Threading;
+using System.Threading.Tasks;
+using Android.Content;
+using Android.Graphics;
+
+namespace Xamarin.Forms.Platform.Android
+{
+ public sealed class ImageLoaderSourceHandler : IImageSourceHandler
+ {
+ public async Task<Bitmap> LoadImageAsync(ImageSource imagesource, Context context, CancellationToken cancelationToken = default(CancellationToken))
+ {
+ var imageLoader = imagesource as UriImageSource;
+ if (imageLoader != null && imageLoader.Uri != null)
+ {
+ using(Stream imageStream = await imageLoader.GetStreamAsync(cancelationToken).ConfigureAwait(false))
+ return await BitmapFactory.DecodeStreamAsync(imageStream).ConfigureAwait(false);
+ }
+ return null;
+ }
+ }
+} \ No newline at end of file