Incorrect image orientation using MediaPicker CapturePhoto on iOS
See original GitHub issueDescription
When using MediaPicker.Default.CapturePhotoAsync() on iOS, the image data from FileResult.OpenReadAsync() gets converted to PNG format with no orientation flag to correctly display the final result.
Many smartphones capture photos using one consistent orientation, and then set the orientation using a flag in the EXIF metadata for the image. This is usually not a problem if the orientation flag is allowed to remain inside the image. Unfortunately, when the PNG conversion occurs with CapturePhotoAsync(), the resulting image data does not contain any orientation flag to properly rotate the photo.
There are two ways to fix this:
- Provide the orientation flag within the PNG data
- Perform the correct image rotate+flip internally before returning PNG data without an orientation flag
Option 1 would probably be the quickest way to fix this and require less processing time.
Steps to Reproduce
Just set up a quick Maui project with a button and an image view. Use MediaPicker.CapturePhoto to take a photo with an iOS device (might need to try different device rotations/orientations). Set the “Source” property of the image to the file result. Code for button click handler method body is below:
var photo = await MediaPicker.Default.CapturePhotoAsync();
var stream = await photo.OpenReadAsync();
var img = ImageSource.FromStream(() => { return stream; });
imgTest.Source = img;
Version with bug
.NET 6.0.400-preview.22330.6
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
15.6
Did you find any workaround?
The only workaround is to take the photo outside the app, then use MediaPicker.Default.PickPhotoAsync() to choose the file (no PNG conversion happens that way).
Relevant log output
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:9
- Comments:13
I am having the same problem. It baffles me why this has been moved to the backlog when it is a serious problem. There is currently no feasible work around
With Xamarin Forms I solved it this way.
Android:
iOS: