Implement zoom start position. Closes #92. Rapid decoder properly throws an error when it fails to decode.

This commit is contained in:
inorichi
2016-02-04 17:16:47 +01:00
parent 6aa07dd17e
commit 391550f49a
16 changed files with 120 additions and 11 deletions

View File

@ -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");
}
}