Catch exceptions in Zoom.java

This commit is contained in:
misaochan 2018-05-29 18:30:17 +10:00
parent 50b674f221
commit 0d282af0e6

View file

@ -15,6 +15,8 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import timber.log.Timber;
public class Zoom { public class Zoom {
private View thumbView; private View thumbView;
@ -23,7 +25,6 @@ public class Zoom {
private ContentResolver contentResolver; private ContentResolver contentResolver;
private FrameLayout flContainer; private FrameLayout flContainer;
Zoom(View thumbView, FrameLayout flContainer, InputStream input, Uri imageUri, ContentResolver contentResolver) { Zoom(View thumbView, FrameLayout flContainer, InputStream input, Uri imageUri, ContentResolver contentResolver) {
this.thumbView = thumbView; this.thumbView = thumbView;
this.input = input; this.input = input;
@ -36,12 +37,16 @@ public class Zoom {
Bitmap scaled = null; Bitmap scaled = null;
BitmapRegionDecoder decoder = null; BitmapRegionDecoder decoder = null;
Bitmap bitmap = null;
try { try {
decoder = BitmapRegionDecoder.newInstance(input, false); decoder = BitmapRegionDecoder.newInstance(input, false);
bitmap = decoder.decodeRegion(new Rect(10, 10, 50, 50), null);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Timber.e(e);
} catch (NullPointerException e) {
Timber.e(e);
} }
Bitmap bitmap = decoder.decodeRegion(new Rect(10, 10, 50, 50), null);
try { try {
//Compress the Image //Compress the Image
System.gc(); System.gc();
@ -55,7 +60,9 @@ public class Zoom {
long calWidth = (long) ((width * maxMemory) / (bitmapByteCount * 1.1)); long calWidth = (long) ((width * maxMemory) / (bitmapByteCount * 1.1));
scaled = Bitmap.createScaledBitmap(bitmap, (int) Math.min(width, calWidth), (int) Math.min(height, calHeight), true); scaled = Bitmap.createScaledBitmap(bitmap, (int) Math.min(width, calWidth), (int) Math.min(height, calHeight), true);
} catch (IOException e) { } catch (IOException e) {
Timber.e(e);
} catch (NullPointerException e) { } catch (NullPointerException e) {
Timber.e(e);
scaled = bitmap; scaled = bitmap;
} }
return scaled; return scaled;