From e8acc31cfbe33f8cf5126bcedd2913ad3f2e6d5d Mon Sep 17 00:00:00 2001 From: Killer <616522635@qq.com> Date: Thu, 23 Jul 2015 23:51:59 +0800 Subject: [PATCH 1/2] when we set fixed aspect ratio ,if the crop are not square,and the exifRotation are 90 or 270,the crop will error. --- .../soundcloud/android/crop/CropImageActivity.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 62a1596a..8c92f5db 100644 --- a/lib/src/main/java/com/soundcloud/android/crop/CropImageActivity.java +++ b/lib/src/main/java/com/soundcloud/android/crop/CropImageActivity.java @@ -325,6 +325,14 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) { RectF adjusted = new RectF(); matrix.mapRect(adjusted, new RectF(rect)); + //when your picture are not square,if the exifRotation is 90 or 270, + //the outWidth and outHeight showld be interchanged + if (exifRotation==90||exifRotation==270){ + int temp=outWidth; + outWidth=outHeight; + outHeight=temp; + } + // Adjust to account for origin at 0,0 adjusted.offset(adjusted.left < 0 ? width : 0, adjusted.top < 0 ? height : 0); rect = new Rect((int) adjusted.left, (int) adjusted.top, (int) adjusted.right, (int) adjusted.bottom); @@ -335,6 +343,9 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) { if (rect.width() > outWidth || rect.height() > outHeight) { Matrix matrix = new Matrix(); matrix.postScale((float) outWidth / rect.width(), (float) outHeight / rect.height()); + + //if the picture's exifRotation !=0 ,they should be go to adjust + matrix.postRotate(exifRotation); croppedImage = Bitmap.createBitmap(croppedImage, 0, 0, croppedImage.getWidth(), croppedImage.getHeight(), matrix, true); } } catch (IllegalArgumentException e) { From 66c5f838b04f2cd0bf59f2dba16372b406c6b48b Mon Sep 17 00:00:00 2001 From: Killer <616522635@qq.com> Date: Fri, 24 Jul 2015 10:03:55 +0800 Subject: [PATCH 2/2] 1)if the picture need not to be scale, they also neet to be rotate to 0 degrees 2)modified the annotation --- .../com/soundcloud/android/crop/CropImageActivity.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 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 8c92f5db..0a350c0d 100644 --- a/lib/src/main/java/com/soundcloud/android/crop/CropImageActivity.java +++ b/lib/src/main/java/com/soundcloud/android/crop/CropImageActivity.java @@ -325,7 +325,7 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) { RectF adjusted = new RectF(); matrix.mapRect(adjusted, new RectF(rect)); - //when your picture are not square,if the exifRotation is 90 or 270, + //if the cutting box are rectangle( outWidth != outHeight ),and the exifRotation is 90 or 270, //the outWidth and outHeight showld be interchanged if (exifRotation==90||exifRotation==270){ int temp=outWidth; @@ -344,7 +344,12 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) { Matrix matrix = new Matrix(); matrix.postScale((float) outWidth / rect.width(), (float) outHeight / rect.height()); - //if the picture's exifRotation !=0 ,they should be go to adjust + //if the picture's exifRotation !=0 ,they should be rotate to 0 degrees + matrix.postRotate(exifRotation); + croppedImage = Bitmap.createBitmap(croppedImage, 0, 0, croppedImage.getWidth(), croppedImage.getHeight(), matrix, true); + }else{ + //if the picture need not to be scale, they also neet to be rotate to 0 degrees + Matrix matrix = new Matrix(); matrix.postRotate(exifRotation); croppedImage = Bitmap.createBitmap(croppedImage, 0, 0, croppedImage.getWidth(), croppedImage.getHeight(), matrix, true); }