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)) {

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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.