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 { // This is set to true when run under designer context internal static bool DecodeSynchronously { get; set; } public async Task LoadImageAsync(ImageSource imagesource, Context context, CancellationToken cancelationToken = default(CancellationToken)) { string file = ((FileImageSource)imagesource).File; if (File.Exists (file)) return !DecodeSynchronously ? (await BitmapFactory.DecodeFileAsync (file).ConfigureAwait (false)) : BitmapFactory.DecodeFile (file); else return !DecodeSynchronously ? (await context.Resources.GetBitmapAsync (file).ConfigureAwait (false)) : context.Resources.GetBitmap (file); } } }