diff --git a/packages/image_picker/CHANGELOG.md b/packages/image_picker/CHANGELOG.md index 01d5490f7a5b..418d3a0a57d6 100644 --- a/packages/image_picker/CHANGELOG.md +++ b/packages/image_picker/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.1+10 + +* iOS: Fix image orientation problems when scaling images. + ## 0.6.1+9 * Remove AndroidX warning. diff --git a/packages/image_picker/ios/Classes/FLTImagePickerImageUtil.m b/packages/image_picker/ios/Classes/FLTImagePickerImageUtil.m index 241db72a68cf..ab765208d0bc 100644 --- a/packages/image_picker/ios/Classes/FLTImagePickerImageUtil.m +++ b/packages/image_picker/ios/Classes/FLTImagePickerImageUtil.m @@ -76,6 +76,20 @@ + (UIImage *)scaledImage:(UIImage *)image scale:1 orientation:UIImageOrientationUp]; + // The image orientation is manually set to UIImageOrientationUp which swapped the aspect ratio in + // some scenarios. For example, when the original image has orientation left, the horizontal + // pixels should be scaled to `width` and the vertical pixels should be scaled to `height`. After + // setting the orientation to up, we end up scaling the horizontal pixels to `height` and vertical + // to `width`. Below swap will solve this issue. + if ([image imageOrientation] == UIImageOrientationLeft || + [image imageOrientation] == UIImageOrientationRight || + [image imageOrientation] == UIImageOrientationLeftMirrored || + [image imageOrientation] == UIImageOrientationRightMirrored) { + double temp = width; + width = height; + height = temp; + } + UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), NO, 1.0); [imageToScale drawInRect:CGRectMake(0, 0, width, height)]; diff --git a/packages/image_picker/pubspec.yaml b/packages/image_picker/pubspec.yaml index f3ed31d4d007..93379d32fe7e 100755 --- a/packages/image_picker/pubspec.yaml +++ b/packages/image_picker/pubspec.yaml @@ -5,7 +5,7 @@ authors: - Flutter Team - Rhodes Davis Jr. homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker -version: 0.6.1+9 +version: 0.6.1+10 flutter: plugin: