java.lang.Object | |
↳ | 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.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Decodes a rectangle region in the image specified by rect.
| |||||||||||
Returns the original image's height
| |||||||||||
Returns the original image's width
| |||||||||||
Returns true if this region decoder has been recycled.
| |||||||||||
Create a BitmapRegionDecoder from a file path.
| |||||||||||
Create a BitmapRegionDecoder from an input stream.
| |||||||||||
Create a BitmapRegionDecoder from the file descriptor.
| |||||||||||
Create a BitmapRegionDecoder from the specified byte array.
| |||||||||||
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Decodes a rectangle region in the image specified by rect.
rect | The rectangle that specified the region to be decode. |
---|---|
options | null-ok; Options that control downsampling. inPurgeable is not supported. |
Returns true if this region decoder has been recycled. If so, then it is an error to try use its method.
Create a BitmapRegionDecoder from a file path. Currently only the JPEG and PNG formats are supported.
pathName | complete path name for the file to be decoded. |
---|---|
isShareable | 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. |
IOException | if the image format is not supported or can not be decoded. |
---|
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.
is | The input stream that holds the raw data to be decoded into a BitmapRegionDecoder. |
---|---|
isShareable | 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. |
IOException | if the image format is not supported or can not be decoded.
Prior to |
---|
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.
fd | The file descriptor containing the data to decode |
---|---|
isShareable | 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. |
IOException | if the image format is not supported or can not be decoded. |
---|
Create a BitmapRegionDecoder from the specified byte array. Currently only the JPEG and PNG formats are supported.
data | byte array of compressed image data. |
---|---|
offset | offset into data for where the decoder should begin parsing. |
length | the number of bytes, beginning at offset, to parse |
isShareable | 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. |
IOException | if the image format is not supported or can not be decoded. |
---|
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.
Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.
Note that objects that override finalize
are significantly more expensive than
objects that don't. Finalizers may be run a long time after the object is no longer
reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup.
Note also that finalizers are run on a single VM-wide finalizer thread,
so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary
for a class that has a native peer and needs to call a native method to destroy that peer.
Even then, it's better to provide an explicit close
method (and implement
Closeable
), and insist that callers manually dispose of instances. This
works well for something like files, but less well for something like a BigInteger
where typical calling code would have to deal with lots of temporaries. Unfortunately,
code that creates lots of temporaries is the worst kind of code from the point of view of
the single finalizer thread.
If you must use finalizers, consider at least providing your own
ReferenceQueue
and having your own thread process that queue.
Unlike constructors, finalizers are not automatically chained. You are responsible for
calling super.finalize()
yourself.
Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.
Throwable |
---|