public class SkiaImageRegionDecoder extends Object implements ImageRegionDecoder
ImageRegionDecoder
using Android's BitmapRegionDecoder, based on the Skia library. This
works well in most circumstances and has reasonable performance due to the cached decoder instance,
however it has some problems with grayscale, indexed and CMYK images.
A ReadWriteLock is used to delegate responsibility for multi threading behaviour to the
BitmapRegionDecoder instance on SDK >= 21, whilst allowing this class to block until no
tiles are being loaded before recycling the decoder. In practice, BitmapRegionDecoder is
synchronized internally so this has no real impact on performance.| Constructor and Description |
|---|
SkiaImageRegionDecoder() |
SkiaImageRegionDecoder(Bitmap.Config bitmapConfig) |
| Modifier and Type | Method and Description |
|---|---|
Bitmap |
decodeRegion(Rect sRect,
int sampleSize)
Decode a region of the image with the given sample size.
|
Point |
init(Context context,
Uri uri)
Initialise the decoder.
|
boolean |
isReady()
Status check.
|
void |
recycle()
This method will be called when the decoder is no longer required.
|
public SkiaImageRegionDecoder()
public SkiaImageRegionDecoder(Bitmap.Config bitmapConfig)
public Point init(Context context, Uri uri) throws Exception
ImageRegionDecoderfile:///scard/picture.jpg
file:///android_asset/picture.png
android.resource://com.example.app/drawable/pictureinit in interface ImageRegionDecodercontext - Application context. A reference may be held, but must be cleared on recycle.uri - URI of the image.Exception - if initialisation fails.public Bitmap decodeRegion(Rect sRect, int sampleSize)
ImageRegionDecoder
Decode a region of the image with the given sample size. This method is called off the UI
thread so it can safely load the image on the current thread. It is called from
AsyncTasks running in an executor that may have multiple threads, so
implementations must be thread safe. Adding synchronized to the method signature
is the simplest way to achieve this, but bear in mind the ImageRegionDecoder.recycle() method can be
called concurrently.
See SkiaImageRegionDecoder and SkiaPooledImageRegionDecoder for examples of
internal locking and synchronization.
decodeRegion in interface ImageRegionDecodersRect - Source image rectangle to decode.sampleSize - Sample size.public boolean isReady()
ImageRegionDecoderisReady in interface ImageRegionDecoderpublic void recycle()
ImageRegionDecoderrecycle in interface ImageRegionDecoder