Skip to content

Commit f5dfd44

Browse files
committed
Hotfix of Samsung devices issue based on jdamcd#146
1 parent f4b2d25 commit f5dfd44

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/src/main/java/com/soundcloud/android/crop/CropImageActivity.java

+17
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
339339
RectF adjusted = new RectF();
340340
matrix.mapRect(adjusted, new RectF(rect));
341341

342+
//if the cutting box are rectangle( outWidth != outHeight ),and the exifRotation is 90 or 270,
343+
//the outWidth and outHeight should be interchanged
344+
if (exifRotation==90||exifRotation==270){
345+
int temp = outWidth;
346+
outWidth = outHeight;
347+
outHeight = temp;
348+
}
349+
342350
// Adjust to account for origin at 0,0
343351
adjusted.offset(adjusted.left < 0 ? width : 0, adjusted.top < 0 ? height : 0);
344352
rect = new Rect((int) adjusted.left, (int) adjusted.top, (int) adjusted.right, (int) adjusted.bottom);
@@ -349,8 +357,17 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
349357
if (croppedImage != null && (rect.width() > outWidth || rect.height() > outHeight)) {
350358
Matrix matrix = new Matrix();
351359
matrix.postScale((float) outWidth / rect.width(), (float) outHeight / rect.height());
360+
361+
//If the picture's exifRotation !=0 ,they should be rotated to 0 degrees
362+
matrix.postRotate(exifRotation);
363+
croppedImage = Bitmap.createBitmap(croppedImage, 0, 0, croppedImage.getWidth(), croppedImage.getHeight(), matrix, true);
364+
} else {
365+
//if the picture need not to be scale, they also need to be rotate to 0 degrees
366+
Matrix matrix = new Matrix();
367+
matrix.postRotate(exifRotation);
352368
croppedImage = Bitmap.createBitmap(croppedImage, 0, 0, croppedImage.getWidth(), croppedImage.getHeight(), matrix, true);
353369
}
370+
354371
} catch (IllegalArgumentException e) {
355372
// Rethrow with some extra information
356373
throw new IllegalArgumentException("Rectangle " + rect + " is outside of the image ("

0 commit comments

Comments
 (0)