@@ -325,6 +325,14 @@ private Bitmap decodeRegionCrop(Rect rect, int outWidth, int outHeight) {
325325 RectF adjusted = new RectF ();
326326 matrix .mapRect (adjusted , new RectF (rect ));
327327
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+
328336 // Adjust to account for origin at 0,0
329337 adjusted .offset (adjusted .left < 0 ? width : 0 , adjusted .top < 0 ? height : 0 );
330338 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) {
335343 if (rect .width () > outWidth || rect .height () > outHeight ) {
336344 Matrix matrix = new Matrix ();
337345 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 );
338354 croppedImage = Bitmap .createBitmap (croppedImage , 0 , 0 , croppedImage .getWidth (), croppedImage .getHeight (), matrix , true );
339355 }
340356 } catch (IllegalArgumentException e ) {
0 commit comments