O'Reilly logo

Xamarin Mobile Development for Android Cookbook by Matthew Leibowitz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required