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! |
decodeRegion(rect: Rect!, options: BitmapFactory.Options!)Decodes a rectangle region in the image specified by rect. |
| Int |
Returns the original image's height |
| Int |
getWidth()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, : Boolean)Create a BitmapRegionDecoder from the specified byte array. |
| static BitmapRegionDecoder! |
newInstance(fd: FileDescriptor!, : Boolean)Create a BitmapRegionDecoder from the file descriptor. |
| static BitmapRegionDecoder! |
newInstance(is: InputStream!, : Boolean)Create a BitmapRegionDecoder from an input stream. |
| static BitmapRegionDecoder! |
newInstance(pathName: String!, : Boolean)Create a BitmapRegionDecoder from a file path. |
| Unit |
recycle()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 |
finalize() |
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. |
| 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 |
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(
data: ByteArray!,
offset: Int,
length: Int,
: 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
static fun newInstance(
fd: FileDescriptor!,
: 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
static fun newInstance(
is: InputStream!,
: 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 |
newInstance
static fun newInstance(
pathName: String!,
: 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
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 |