Handling high-resolution images

Working with images often requires the app to be able to load very large images. Photos are especially large due to modern cameras producing high resolution images from excellent camera hardware.

How to do it...

We can easily load images from files, resources, or remote sources using the BitmapFactory type:

  1. All we need in order to load a bitmap is the path or stream and one of the decode methods, such as DecodeStreamAsync:
    using (var stream = Assets.Open("bigimage.png"))
    using (var bitmap = await BitmapFactory.DecodeStreamAsync(stream)) {
      imageView.SetImageBitmap(bitmap);
    }

As images can be quite large, both in resolution and in memory size, it is often better to reduce them using subsampling:

  1. When using subsampling, ...

Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.