BitmapRegionDecoder
class 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 |
Create a BitmapRegionDecoder from the file descriptor.
|
static BitmapRegionDecoder |
Create a BitmapRegionDecoder from the specified byte array.
|
static BitmapRegionDecoder |
Create a BitmapRegionDecoder from the specified byte array.
|
static BitmapRegionDecoder |
Create a BitmapRegionDecoder from the file descriptor.
|
static BitmapRegionDecoder? |
Create a BitmapRegionDecoder from an input stream.
|
static BitmapRegionDecoder? |
Create a BitmapRegionDecoder from an input stream.
|
static BitmapRegionDecoder |
Create a BitmapRegionDecoder from a file path.
|
static BitmapRegionDecoder |
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.
|
Public methods
decodeRegion
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. |
getHeight
fun getHeight(): Int
Returns the original image's height
getWidth
fun getWidth(): Int
Returns the original image's width
isRecycled
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
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 . |
Exceptions |
java.io.IOException |
if the image format is not supported or can not be decoded. |
newInstance
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 |
Exceptions |
java.io.IOException |
if the image format is not supported or can not be decoded. |
newInstance
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 . |
Exceptions |
java.io.IOException |
if the image format is not supported or can not be decoded. |
newInstance
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.
Exceptions |
java.io.IOException |
if the image format is not supported or can not be decoded. |
newInstance
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 . |
Exceptions |
java.io.IOException |
if the image format is not supported or can not be decoded. |
newInstance
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. |
Exceptions |
java.io.IOException |
if the image format is not supported or can not be decoded. |
newInstance
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 . |
Exceptions |
java.io.IOException |
if the image format is not supported or can not be decoded. |
newInstance
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. |
Exceptions |
java.io.IOException |
if the image format is not supported or can not be decoded. |
recycle
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
protected fun finalize(): Unit
Exceptions |
java.lang.Throwable |
the Exception raised by this method |