RegionDecoderImageSource

ImageSource that decodes regions of an encoded image (JPEG, PNG or WebP) using a BitmapRegionDecoder, so the whole image never needs to be held in memory.

The encoded image is read through opener, which is invoked each time the source needs to read the image: once to read the EXIF orientation and once to open the region decoder, both on creation and on every contentChanged call. Streams returned by opener are always closed by this class.

A region decoder created from a stream keeps a copy of the whole encoded image in memory. The factories in ImageSources avoid that copy for files and file backed URIs.

Creating an instance reads the image header, so it should be done away from the UI thread when the image is large or comes from a slow provider.

Throws

if the image cannot be read or its format is not supported by BitmapRegionDecoder.

Constructors

Link copied to clipboard
constructor(opener: () -> InputStream)

Creates a source reading the encoded image from a stream.

Properties

Link copied to clipboard
open override var orientation: Int

EXIF orientation of the image, or ExifInterface.ORIENTATION_NORMAL when it is unknown.

Link copied to clipboard
open override val storedHeight: Int

Height of the image in stored pixels, before applying orientation.

Link copied to clipboard
open override val storedWidth: Int

Width of the image in stored pixels, before applying orientation.

Functions

Link copied to clipboard
open override fun close()

Releases the region decoder. Further calls to decodeRegion return null.

Link copied to clipboard
open override fun contentChanged()

Re-reads the image through the opener, closing the previous region decoder.

Link copied to clipboard
open override fun decodeRegion(region: Rect, sampleSize: Int, config: Bitmap.Config, reuse: Bitmap?): Bitmap?

Decodes a region of the image.