Skip to content

Instantly share code, notes, and snippets.

@jonathanpeppers
Created February 13, 2018 20:32
Show Gist options
  • Save jonathanpeppers/5421082514fbf9dcfdd250ade3c9807b to your computer and use it in GitHub Desktop.
Save jonathanpeppers/5421082514fbf9dcfdd250ade3c9807b to your computer and use it in GitHub Desktop.
public async Task<Bitmap> LoadImageAsync(ImageSource imagesource, Context context, CancellationToken cancelationToken = default(CancellationToken))
{
string file = ((FileImageSource)imagesource).File;
Bitmap bitmap;
if (File.Exists (file))
bitmap = !DecodeSynchronously ? (await BitmapFactory.DecodeFileAsync (file).ConfigureAwait (false)) : BitmapFactory.DecodeFile (file);
else
bitmap = !DecodeSynchronously ? (await context.Resources.GetBitmapAsync (file).ConfigureAwait (false)) : context.Resources.GetBitmap (file);
if (bitmap == null)
{
Log.Warning(nameof(FileImageSourceHandler), "Could not find image or image file was invalid: {0}", imagesource);
}
return bitmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment