From e04feb59d1c9c22da3bd558804c396df90d0bffc Mon Sep 17 00:00:00 2001 From: Amdis Liu Date: Mon, 11 Apr 2016 23:44:26 +0800 Subject: [PATCH] Fix certain JPEG files are failed to be decoded with BitmapRegionDecoder - this is a known issue of Google : https://code.google.com/p/android/issues/detail?id=77195 --- .../com/soundcloud/android/crop/CropImageActivity.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/com/soundcloud/android/crop/CropImageActivity.java b/lib/src/main/java/com/soundcloud/android/crop/CropImageActivity.java index 97a0466a..77eb54af 100644 --- a/lib/src/main/java/com/soundcloud/android/crop/CropImageActivity.java +++ b/lib/src/main/java/com/soundcloud/android/crop/CropImageActivity.java @@ -325,9 +325,10 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) { Bitmap croppedImage = null; try { is = getContentResolver().openInputStream(sourceUri); - BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(is, false); - final int width = decoder.getWidth(); - final int height = decoder.getHeight(); + croppedImage = BitmapFactory.decodeStream(is); + final int width = croppedImage.getWidth(); + final int height = croppedImage.getHeight(); + if (exifRotation != 0) { // Adjust crop area to account for image rotation @@ -343,7 +344,8 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) { } try { - croppedImage = decoder.decodeRegion(rect, new BitmapFactory.Options()); + croppedImage = Bitmap.createBitmap(croppedImage, rect.left, rect.top, rect.width(), rect.height()); + if (croppedImage != null && (rect.width() > outWidth || rect.height() > outHeight)) { Matrix matrix = new Matrix(); matrix.postScale((float) outWidth / rect.width(), (float) outHeight / rect.height());