-
Notifications
You must be signed in to change notification settings - Fork 1.2k
04. Custom decoders
Android's BitmapRegionDecoder
class is based on the Skia library. Some users have reported problems with this library, particularly when displaying CYMK JPGs and grayscale PNGs. Unfortunately it seems to be less reliable in recent versions of Android. If you don't control the format of the images displayed in your app (for example, they are user generated content) you may require a more reliable decoder.
To use your own decoder based on a different library, implement the ImageRegionDecoder
class (do not include a constructor) and enable it using this call:
imageView.setDecoderClass(MyImageRegionDecoder.class);
As an example, see the RapidImageRegionDecoder
class, which is based on RapidDecoder. This library is better at decoding grayscale JPG images but does not handle large images as well as BitmapRegionDecoder
- it is significantly slower and more likely to throw out of memory errors. It appears to be very fast and reliable for PNG images. If you can detect the size and type of an image before displaying it, you can use different decoders for different images to get the best results.
Whenever possible, convert your images to a format Android's Skia library can support, and test with a variety of devices.