Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7a6c105

Browse files
owopsChris Yang
authored andcommitted
[image_picker] swap width and height when source image when orientation is left or right (flutter#2070)
1 parent fe49a79 commit 7a6c105

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

packages/image_picker/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.1+10
2+
3+
* iOS: Fix image orientation problems when scaling images.
4+
15
## 0.6.1+9
26

37
* Remove AndroidX warning.

packages/image_picker/ios/Classes/FLTImagePickerImageUtil.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ + (UIImage *)scaledImage:(UIImage *)image
7676
scale:1
7777
orientation:UIImageOrientationUp];
7878

79+
// The image orientation is manually set to UIImageOrientationUp which swapped the aspect ratio in
80+
// some scenarios. For example, when the original image has orientation left, the horizontal
81+
// pixels should be scaled to `width` and the vertical pixels should be scaled to `height`. After
82+
// setting the orientation to up, we end up scaling the horizontal pixels to `height` and vertical
83+
// to `width`. Below swap will solve this issue.
84+
if ([image imageOrientation] == UIImageOrientationLeft ||
85+
[image imageOrientation] == UIImageOrientationRight ||
86+
[image imageOrientation] == UIImageOrientationLeftMirrored ||
87+
[image imageOrientation] == UIImageOrientationRightMirrored) {
88+
double temp = width;
89+
width = height;
90+
height = temp;
91+
}
92+
7993
UIGraphicsBeginImageContextWithOptions(CGSizeMake(width, height), NO, 1.0);
8094
[imageToScale drawInRect:CGRectMake(0, 0, width, height)];
8195

packages/image_picker/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors:
55
- Flutter Team <[email protected]>
66
- Rhodes Davis Jr. <[email protected]>
77
homepage: https://github.com/flutter/plugins/tree/master/packages/image_picker
8-
version: 0.6.1+9
8+
version: 0.6.1+10
99

1010
flutter:
1111
plugin:

0 commit comments

Comments
 (0)