mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-25 18:47:51 +02:00
Implement zoom start position. Closes #92. Rapid decoder properly throws an error when it fails to decode.
This commit is contained in:
@ -6,8 +6,6 @@ import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.davemorrissey.labs.subscaleview.decoder.ImageRegionDecoder;
|
||||
|
||||
import rapid.decoder.BitmapDecoder;
|
||||
|
||||
/**
|
||||
@ -26,15 +24,19 @@ public class RapidImageRegionDecoder implements ImageRegionDecoder {
|
||||
public Point init(Context context, Uri uri) throws Exception {
|
||||
decoder = BitmapDecoder.from(context, uri);
|
||||
decoder.useBuiltInDecoder(true);
|
||||
return new Point(decoder.sourceWidth(), decoder.sourceHeight());
|
||||
int width = decoder.sourceWidth();
|
||||
int height = decoder.sourceHeight();
|
||||
if (width == 0 || height == 0)
|
||||
throw new Exception("Rapid image decoder returned empty image - image format may not be supported");
|
||||
return new Point(width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Bitmap decodeRegion(Rect sRect, int sampleSize) {
|
||||
try {
|
||||
return decoder.reset().region(sRect).scale(sRect.width()/sampleSize, sRect.height()/sampleSize).decode();
|
||||
return decoder.reset().region(sRect).scale(sRect.width() / sampleSize, sRect.height() / sampleSize).decode();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
throw new RuntimeException("Rapid image decoder returned null bitmap - image format may not be supported");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user