Google is committed to advancing racial equity for Black communities. See how.
Added in API level 10

BitmapRegionDecoder

class BitmapRegionDecoder
kotlin.Any
   ↳ android.graphics.BitmapRegionDecoder

BitmapRegionDecoder can be used to decode a rectangle region from an image. BitmapRegionDecoder is particularly useful when an original image is large and you only need parts of the image.

To create a BitmapRegionDecoder, call newInstance(...). Given a BitmapRegionDecoder, users can call decodeRegion() repeatedly to get a decoded Bitmap of the specified region.

Summary

Public methods

Bitmap!

Decodes a rectangle region in the image specified by rect.

Int

Returns the original image's height

Int

Returns the original image's width

Boolean

Returns true if this region decoder has been recycled.

static BitmapRegionDecoder!
newInstance(data: ByteArray!, offset: Int, length: Int, isShareable: Boolean)

Create a BitmapRegionDecoder from the specified byte array.

static BitmapRegionDecoder!
newInstance(fd: FileDescriptor!, isShareable: Boolean)

Create a BitmapRegionDecoder from the file descriptor.

static BitmapRegionDecoder!
newInstance(is: InputStream!, isShareable: Boolean)

Create a BitmapRegionDecoder from an input stream.

static BitmapRegionDecoder!
newInstance(pathName: String!, isShareable: Boolean)

Create a BitmapRegionDecoder from a file path.

Unit

Frees up the memory associated with this region decoder, and mark the region decoder as "dead", meaning it will throw an exception if decodeRegion(), getWidth() or getHeight() is called.

Protected methods

Unit

Public methods

decodeRegion

Added in API level 10
fun decodeRegion(
    rect: Rect!,
    options: BitmapFactory.Options!
): Bitmap!

Decodes a rectangle region in the image specified by rect.

Parameters
rect Rect!: The rectangle that specified the region to be decode.
options BitmapFactory.Options!: null-ok; Options that control downsampling. inPurgeable is not supported.
Return
Bitmap! The decoded bitmap, or null if the image data could not be decoded.
Exceptions
java.lang.IllegalArgumentException if BitmapFactory.Options#inPreferredConfig is android.graphics.Bitmap.Config#HARDWARE and BitmapFactory.Options#inMutable is set, if the specified color space is not ColorSpace.Model#RGB, or if the specified color space's transfer function is not an ColorSpace.Rgb.TransferParameters

getHeight

Added in API level 10
fun getHeight(): Int

Returns the original image's height

getWidth

Added in API level 10
fun getWidth(): Int

Returns the original image's width

isRecycled

Added in API level 10
fun isRecycled(): Boolean

Returns true if this region decoder has been recycled. If so, then it is an error to try use its method.

Return
Boolean true if the region decoder has been recycled

newInstance

Added in API level 10
static fun newInstance(
    data: ByteArray!,
    offset: Int,
    length: Int,
    isShareable: Boolean
): BitmapRegionDecoder!

Create a BitmapRegionDecoder from the specified byte array. Currently only the JPEG and PNG formats are supported.

Parameters
data ByteArray!: byte array of compressed image data.
offset Int: offset into data for where the decoder should begin parsing.
length Int: the number of bytes, beginning at offset, to parse
isShareable Boolean: If this is true, then the BitmapRegionDecoder may keep a shallow reference to the input. If this is false, then the BitmapRegionDecoder will explicitly make a copy of the input data, and keep that. Even if sharing is allowed, the implementation may still decide to make a deep copy of the input data. If an image is progressively encoded, allowing sharing may degrade the decoding speed.
Return
BitmapRegionDecoder! BitmapRegionDecoder, or null if the image data could not be decoded.
Exceptions
java.io.IOException if the image format is not supported or can not be decoded.

newInstance

Added in API level 10
static fun newInstance(
    fd: FileDescriptor!,
    isShareable: Boolean
): BitmapRegionDecoder!

Create a BitmapRegionDecoder from the file descriptor. The position within the descriptor will not be changed when this returns, so the descriptor can be used again as is. Currently only the JPEG and PNG formats are supported.

Parameters
fd FileDescriptor!: The file descriptor containing the data to decode
isShareable Boolean: If this is true, then the BitmapRegionDecoder may keep a shallow reference to the input. If this is false, then the BitmapRegionDecoder will explicitly make a copy of the input data, and keep that. Even if sharing is allowed, the implementation may still decide to make a deep copy of the input data. If an image is progressively encoded, allowing sharing may degrade the decoding speed.
Return
BitmapRegionDecoder! BitmapRegionDecoder, or null if the image data could not be decoded.
Exceptions
java.io.IOException if the image format is not supported or can not be decoded.

newInstance

Added in API level 10
static fun newInstance(
    is: InputStream!,
    isShareable: Boolean
): BitmapRegionDecoder!

Create a BitmapRegionDecoder from an input stream. The stream's position will be where ever it was after the encoded data was read. Currently only the JPEG and PNG formats are supported.

Parameters
is InputStream!: The input stream that holds the raw data to be decoded into a BitmapRegionDecoder.
isShareable Boolean: If this is true, then the BitmapRegionDecoder may keep a shallow reference to the input. If this is false, then the BitmapRegionDecoder will explicitly make a copy of the input data, and keep that. Even if sharing is allowed, the implementation may still decide to make a deep copy of the input data. If an image is progressively encoded, allowing sharing may degrade the decoding speed.
Return
BitmapRegionDecoder! BitmapRegionDecoder, or null if the image data could not be decoded.
Exceptions
java.io.IOException if the image format is not supported or can not be decoded.

Prior to android.os.Build.VERSION_CODES#KITKAT, if InputStream#markSupported returns true, is.mark(1024) would be called. As of android.os.Build.VERSION_CODES#KITKAT, this is no longer the case.

newInstance

Added in API level 10
static fun newInstance(
    pathName: String!,
    isShareable: Boolean
): BitmapRegionDecoder!

Create a BitmapRegionDecoder from a file path. Currently only the JPEG and PNG formats are supported.

Parameters
pathName String!: complete path name for the file to be decoded.
isShareable Boolean: If this is true, then the BitmapRegionDecoder may keep a shallow reference to the input. If this is false, then the BitmapRegionDecoder will explicitly make a copy of the input data, and keep that. Even if sharing is allowed, the implementation may still decide to make a deep copy of the input data. If an image is progressively encoded, allowing sharing may degrade the decoding speed.
Return
BitmapRegionDecoder! BitmapRegionDecoder, or null if the image data could not be decoded.
Exceptions
java.io.IOException if the image format is not supported or can not be decoded.

recycle

Added in API level 10
fun recycle(): Unit

Frees up the memory associated with this region decoder, and mark the region decoder as "dead", meaning it will throw an exception if decodeRegion(), getWidth() or getHeight() is called.

This operation cannot be reversed, so it should only be called if you are sure there are no further uses for the region decoder. This is an advanced call, and normally need not be called, since the normal GC process will free up this memory when there are no more references to this region decoder.

Protected methods

finalize

Added in API level 10
protected fun finalize(): Unit
Exceptions
java.lang.Throwable the Exception raised by this method