mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Minor changes
This commit is contained in:
parent
b170520370
commit
7e79a377cc
6 changed files with 7 additions and 12 deletions
|
@ -6,6 +6,9 @@ version = '3.4.1'
|
|||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: '*.jar')
|
||||
compile "com.android.support:support-annotations:23.1.1"
|
||||
compile 'rapid.decoder:library:0.3.0'
|
||||
compile 'rapid.decoder:jpeg-decoder:0.3.0'
|
||||
compile 'rapid.decoder:png-decoder:0.3.0'
|
||||
}
|
||||
|
||||
android {
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package com.davemorrissey.labs.subscaleview.decoder;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.davemorrissey.labs.subscaleview.decoder.ImageRegionDecoder;
|
||||
|
||||
import rapid.decoder.BitmapDecoder;
|
||||
|
||||
/**
|
||||
* A very simple implementation of {@link com.davemorrissey.labs.subscaleview.decoder.ImageRegionDecoder}
|
||||
* using the RapidDecoder library (https://github.com/suckgamony/RapidDecoder). For PNGs, this can
|
||||
* give more reliable decoding and better performance. For JPGs, it is slower and can run out of
|
||||
* memory with large images, but has better support for grayscale and CMYK images.
|
||||
*
|
||||
* This is an incomplete and untested implementation provided as an example only.
|
||||
*/
|
||||
public class RapidImageRegionDecoder implements ImageRegionDecoder {
|
||||
|
||||
private BitmapDecoder decoder;
|
||||
|
||||
@Override
|
||||
public Point init(Context context, Uri uri) throws Exception {
|
||||
decoder = BitmapDecoder.from(context, uri);
|
||||
decoder.useBuiltInDecoder(true);
|
||||
return new Point(decoder.sourceWidth(), decoder.sourceHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Bitmap decodeRegion(Rect sRect, int sampleSize) {
|
||||
try {
|
||||
return decoder.reset().region(sRect).scale(sRect.width()/sampleSize, sRect.height()/sampleSize).decode();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
return decoder != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recycle() {
|
||||
BitmapDecoder.destroyMemoryCache();
|
||||
BitmapDecoder.destroyDiskCache();
|
||||
decoder.reset();
|
||||
decoder = null;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue