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(data: ByteArray, offset: Int, length: Int)

Create a BitmapRegionDecoder from the specified byte array.

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

Create a BitmapRegionDecoder from the file descriptor.

static BitmapRegionDecoder

Create a BitmapRegionDecoder from the file descriptor.

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

Create a BitmapRegionDecoder from an input stream.

static BitmapRegionDecoder?

Create a BitmapRegionDecoder from an input stream.

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

Create a BitmapRegionDecoder from a file path.

static BitmapRegionDecoder
newInstance(pathName: String)

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 RGB, or if the specified color space's transfer function is not an ICC parametric curve

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
Deprecated in API level 31
static fun newInstance(
    data: ByteArray,
    offset: Int,
    length: Int,
    isShareable: Boolean
): BitmapRegionDecoder

Deprecated: In favor of newInstance(byte[],int,int)

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

Parameters
data ByteArray: byte array of compressed image data. This value cannot be null.
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: This field has been ignored since Build.VERSION_CODES#GINGERBREAD.
Return
BitmapRegionDecoder This value cannot be null.
Exceptions
java.io.IOException if the image format is not supported or can not be decoded.

newInstance

Added in API level 31
static fun newInstance(
    data: ByteArray,
    offset: Int,
    length: Int
): BitmapRegionDecoder

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

Parameters
data ByteArray: byte array of compressed image data. This value cannot be null.
offset Int: offset into data for where the decoder should begin parsing.
length Int: the number of bytes, beginning at offset, to parse
Return
BitmapRegionDecoder This value cannot be null.
Exceptions
java.io.IOException if the image format is not supported or can not be decoded.

newInstance

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

Deprecated: In favor of newInstance(android.os.ParcelFileDescriptor)

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, PNG, WebP and HEIF formats are supported.

Parameters
fd FileDescriptor: The file descriptor containing the data to decode This value cannot be null.
isShareable Boolean: This field has been ignored since Build.VERSION_CODES#KITKAT.
Return
BitmapRegionDecoder This value cannot be null.
Exceptions
java.io.IOException if the image format is not supported or can not be decoded.

newInstance

Added in API level 31
static fun newInstance(pfd: ParcelFileDescriptor): 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, PNG, WebP and HEIF formats are supported.

Parameters
pfd ParcelFileDescriptor: The parcel file descriptor containing the data to decode This value cannot be null.
Return
BitmapRegionDecoder This value cannot be null.
Exceptions
java.io.IOException if the image format is not supported or can not be decoded.

newInstance

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

Deprecated: In favor of newInstance(java.io.InputStream)

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

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, PNG, WebP and HEIF formats are supported.

Parameters
is InputStream: The input stream that holds the raw data to be decoded into a BitmapRegionDecoder. This value cannot be null.
isShareable Boolean: This field has always been ignored.
Return
BitmapRegionDecoder? A new BitmapRegionDecoder, or null if is is null.
Exceptions
java.io.IOException if the image format is not supported or can not be decoded.

newInstance

Added in API level 31
static fun newInstance(is: InputStream): 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, PNG, WebP and HEIF formats are supported.

Parameters
is InputStream: The input stream that holds the raw data to be decoded into a BitmapRegionDecoder. This value cannot be null.
Return
BitmapRegionDecoder? A new BitmapRegionDecoder, or null if is is null.
Exceptions
java.io.IOException if the image format is not supported or can not be decoded.

newInstance

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

Deprecated: In favor of newInstance(java.lang.String)

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

Parameters
pathName String: complete path name for the file to be decoded. This value cannot be null.
isShareable Boolean: This field has always been ignored.
Return
BitmapRegionDecoder This value cannot be null.
Exceptions
java.io.IOException if the image format is not supported or can not be decoded.

newInstance

Added in API level 31
static fun newInstance(pathName: String): BitmapRegionDecoder

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

Parameters
pathName String: complete path name for the file to be decoded. This value cannot be null.
Return
BitmapRegionDecoder This value cannot be null.
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