-
- All Implemented Interfaces:
-
com.pdfview.subsamplincscaleimageview.decoder.ImageRegionDecoder
public class SkiaImageRegionDecoder implements ImageRegionDecoder
Default implementation of 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 Summary
Constructors Constructor Description SkiaImageRegionDecoder()SkiaImageRegionDecoder(Bitmap.Config bitmapConfig)
-
Method Summary
Modifier and Type Method Description Pointinit(Context context, @NonNull() Uri uri)Initialise the decoder. BitmapdecodeRegion(@NonNull() Rect sRect, int sampleSize)Decode a region of the image with the given sample size. synchronized booleanisReady()Status check. synchronized voidrecycle()This method will be called when the decoder is no longer required. -
-
Constructor Detail
-
SkiaImageRegionDecoder
SkiaImageRegionDecoder()
-
SkiaImageRegionDecoder
SkiaImageRegionDecoder(Bitmap.Config bitmapConfig)
-
-
Method Detail
-
init
@NonNull() Point init(Context context, @NonNull() Uri uri)
Initialise the decoder. When possible, perform initial setup work once in this method. Thedimensions of the image must be returned. The URI can be in one of the following formats:File:
file:///scard/picture.jpgAsset:file:///android_asset/picture.pngResource:android.resource://com.example.app/drawable/picture- Parameters:
context- Application context.uri- URI of the image.
-
decodeRegion
@NonNull() Bitmap decodeRegion(@NonNull() Rect sRect, int sampleSize)
Decode a region of the image with the given sample size. This method is called off the UIthread so it can safely load the image on the current thread. It is called from android.os.AsyncTasks running in an executor that may have multiple threads, soimplementations must be thread safe. Adding
synchronizedto the method signatureis the simplest way to achieve this, but bear in mind the recycle method can becalled concurrently.See SkiaImageRegionDecoder and SkiaPooledImageRegionDecoder for examples ofinternal locking and synchronization.
- Parameters:
sRect- Source image rectangle to decode.sampleSize- Sample size.
-
isReady
synchronized boolean isReady()
Status check. Should return false before initialisation and after recycle.
-
recycle
synchronized void recycle()
This method will be called when the decoder is no longer required. It should clean up any resources still in use.
-
-
-
-