[BUG] CameraView always sets `upper-right` to EXIF orientation tag on iOS
Is there an existing issue for this?
- [X] I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- [X] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
CameraView always sets upper-right to EXIF orientation tag on iOS.
Expected Behavior
CameraView should set the correct orientation value to the EXIF orientation tag.
Steps To Reproduce
We need to view the EXIF tags after creating a photo. The steps below are what I am somewhat familiar with, so if you have a better/easier method, use that.
- Launch project on physical iOS device
- Set breakpoint on MainPage.xaml.cs:39
- Take picture in portrait orientation
- Either copy base64 from Debug output or from variable inspection
- Save base64 in text file on your computer
- Convert base64 into a binary file (does not need a file extension)
- PowerShell:
[IO.File]::WriteAllBytes($path, [Convert]::FromBase64String(<base64 string or Get-Content from file>))
- PowerShell:
- View exif tags (I used
file <filepath>from bash from Git for Windows) - See that the orientation value is always the same
- Repeat steps 3 to 8 from different device orientations
Link to public reproduction project repository
https://github.com/tschbc/CameraViewOrientationUpperRightIssue
Environment
- .NET MAUI CommunityToolkit: 9.0.2
- .NET MAUI CommunityToolkit.Camera: 1.0.3
- OS: iOS 17.5.1
- .NET MAUI: 8.0.70
Anything else?
If you track the device's current rotation yourself and rotate the image data (using something like ImageSharp), then you can correctly orient the picture outside of iOS. It will still be incorrectly rotated in MAUI Image views as long as the orientation value remains.
There are other issues with the CameraView that I may re-use this repro repository for (e.g. StartCameraPreview throws exceptions when taking a picture, and even if you catch those, rapidly taking pictures (as a user, not in code) throws exceptions that cannot be caught, crashing the app.
@brminnick thoughts?
In my journey to try fix this in my project, most resources I've found are for .NET Framework, have a dependency on Windows' System.Drawing namespace, or juggling byte arrays of metadata and "magic values" that I feel is too much of a rabbit hole for me currently.
There's an additional problem: if I write EXIF tags to the image after it's created, it gets re-compressed (using the only library I could find that fits my project).
Hello guys, anything on this? I can confirm this bug is really there, and believe it is also linked to (causes) this issue
Planning to do a final test with https://github.com/CommunityToolkit/Maui/releases/tag/2.0.1-camera, I'll close this issue once we confirm.
We've tested the fix using a build from the PR branch and it has been working well. We haven't tested using the official toolkit release because we aren't ready to upgrade to MAUI 9.