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:
- 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:
- When using subsampling, we need to provide extra options to the decode methods. This requires the use of the
BitmapFactory.Options
type:var options = new BitmapFactory.Options();
- Once we have the options, we can set various properties. If we want to load just the...