@@ -325,6 +325,14 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
325
325
RectF adjusted = new RectF ();
326
326
matrix .mapRect (adjusted , new RectF (rect ));
327
327
328
+ //if the cutting box are rectangle( outWidth != outHeight ),and the exifRotation is 90 or 270,
329
+ //the outWidth and outHeight should be interchanged
330
+ if (exifRotation ==90 ||exifRotation ==270 ){
331
+ int temp =outWidth ;
332
+ outWidth =outHeight ;
333
+ outHeight =temp ;
334
+ }
335
+
328
336
// Adjust to account for origin at 0,0
329
337
adjusted .offset (adjusted .left < 0 ? width : 0 , adjusted .top < 0 ? height : 0 );
330
338
rect = new Rect ((int ) adjusted .left , (int ) adjusted .top , (int ) adjusted .right , (int ) adjusted .bottom );
@@ -335,6 +343,14 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
335
343
if (rect .width () > outWidth || rect .height () > outHeight ) {
336
344
Matrix matrix = new Matrix ();
337
345
matrix .postScale ((float ) outWidth / rect .width (), (float ) outHeight / rect .height ());
346
+
347
+ //If the picture's exifRotation !=0 ,they should be rotated to 0 degrees
348
+ matrix .postRotate (exifRotation );
349
+ croppedImage = Bitmap .createBitmap (croppedImage , 0 , 0 , croppedImage .getWidth (), croppedImage .getHeight (), matrix , true );
350
+ } else {
351
+ //if the picture need not to be scale, they also need to be rotate to 0 degrees
352
+ Matrix matrix = new Matrix ();
353
+ matrix .postRotate (exifRotation );
338
354
croppedImage = Bitmap .createBitmap (croppedImage , 0 , 0 , croppedImage .getWidth (), croppedImage .getHeight (), matrix , true );
339
355
}
340
356
} catch (IllegalArgumentException e ) {
0 commit comments