Prevent crash

pull/177/head
M66B 6 years ago
parent fc3d4a3d11
commit 66b6bea31d

@ -593,13 +593,7 @@ class ImageHelper {
while (options.outWidth / factor > scaleToPixels) while (options.outWidth / factor > scaleToPixels)
factor *= 2; factor *= 2;
Matrix rotation = null; Matrix rotation = getImageRotation(file);
try {
rotation = getImageRotation(file);
} catch (IOException ex) {
Log.w(ex);
}
if (factor > 1 || rotation != null) { if (factor > 1 || rotation != null) {
Log.i("Decode image factor=" + factor); Log.i("Decode image factor=" + factor);
options.inJustDecodeBounds = false; options.inJustDecodeBounds = false;
@ -618,40 +612,55 @@ class ImageHelper {
return BitmapFactory.decodeFile(file.getAbsolutePath()); return BitmapFactory.decodeFile(file.getAbsolutePath());
} }
static Matrix getImageRotation(File file) throws IOException { static Matrix getImageRotation(File file) {
ExifInterface exif = new ExifInterface(file.getAbsolutePath()); try {
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); ExifInterface exif = new ExifInterface(file.getAbsolutePath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
Matrix matrix = new Matrix();
switch (orientation) { Matrix matrix = new Matrix();
case ExifInterface.ORIENTATION_NORMAL: switch (orientation) {
return null; case ExifInterface.ORIENTATION_NORMAL:
case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: return null;
matrix.setScale(-1, 1); case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
return matrix; matrix.setScale(-1, 1);
case ExifInterface.ORIENTATION_FLIP_VERTICAL: return matrix;
matrix.setRotate(180); case ExifInterface.ORIENTATION_FLIP_VERTICAL:
matrix.postScale(-1, 1); matrix.setRotate(180);
return matrix; matrix.postScale(-1, 1);
case ExifInterface.ORIENTATION_TRANSPOSE: return matrix;
matrix.setRotate(90); case ExifInterface.ORIENTATION_TRANSPOSE:
matrix.postScale(-1, 1); matrix.setRotate(90);
return matrix; matrix.postScale(-1, 1);
case ExifInterface.ORIENTATION_TRANSVERSE: return matrix;
matrix.setRotate(-90); case ExifInterface.ORIENTATION_TRANSVERSE:
matrix.postScale(-1, 1); matrix.setRotate(-90);
return matrix; matrix.postScale(-1, 1);
case ExifInterface.ORIENTATION_ROTATE_90: return matrix;
matrix.setRotate(90); case ExifInterface.ORIENTATION_ROTATE_90:
return matrix; matrix.setRotate(90);
case ExifInterface.ORIENTATION_ROTATE_180: return matrix;
matrix.setRotate(180); case ExifInterface.ORIENTATION_ROTATE_180:
return matrix; matrix.setRotate(180);
case ExifInterface.ORIENTATION_ROTATE_270: return matrix;
matrix.setRotate(-90); case ExifInterface.ORIENTATION_ROTATE_270:
return matrix; matrix.setRotate(-90);
default: return matrix;
return null; default:
return null;
}
} catch (Throwable ex /* IOException */) {
/*
java.lang.RuntimeException: setDataSourceCallback failed: status = 0x80000000
java.lang.RuntimeException: setDataSourceCallback failed: status = 0x80000000
at android.media.MediaMetadataRetriever._setDataSource(Native Method)
at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:226)
at androidx.exifinterface.media.ExifInterface.getHeifAttributes(SourceFile:5716)
at androidx.exifinterface.media.ExifInterface.loadAttributes(SourceFile:4556)
at androidx.exifinterface.media.ExifInterface.initForFilename(SourceFile:5195)
at androidx.exifinterface.media.ExifInterface.<init>(SourceFile:3926)
*/
Log.w(ex);
return null;
} }
} }

Loading…
Cancel
Save