@@ -339,6 +339,14 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
339
339
RectF adjusted = new RectF ();
340
340
matrix .mapRect (adjusted , new RectF (rect ));
341
341
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
+
342
350
// Adjust to account for origin at 0,0
343
351
adjusted .offset (adjusted .left < 0 ? width : 0 , adjusted .top < 0 ? height : 0 );
344
352
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) {
349
357
if (croppedImage != null && (rect .width () > outWidth || rect .height () > outHeight )) {
350
358
Matrix matrix = new Matrix ();
351
359
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 );
352
368
croppedImage = Bitmap .createBitmap (croppedImage , 0 , 0 , croppedImage .getWidth (), croppedImage .getHeight (), matrix , true );
353
369
}
370
+
354
371
} catch (IllegalArgumentException e ) {
355
372
// Rethrow with some extra information
356
373
throw new IllegalArgumentException ("Rectangle " + rect + " is outside of the image ("
0 commit comments