Maui icon indicating copy to clipboard operation
Maui copied to clipboard

[BUG] CameraView always sets `upper-right` to EXIF orientation tag on iOS

Open tschbc opened this issue 1 year ago • 2 comments

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.

  1. Launch project on physical iOS device
  2. Set breakpoint on MainPage.xaml.cs:39
  3. Take picture in portrait orientation
  4. Either copy base64 from Debug output or from variable inspection
  5. Save base64 in text file on your computer
  6. 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>))
  7. View exif tags (I used file <filepath> from bash from Git for Windows)
  8. See that the orientation value is always the same
  9. 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.

tschbc avatar Jul 26 '24 15:07 tschbc

@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).

tschbc avatar Aug 12 '24 15:08 tschbc

Hello guys, anything on this? I can confirm this bug is really there, and believe it is also linked to (causes) this issue

polincev avatar Aug 15 '24 13:08 polincev

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.

tschbc avatar Jan 20 '25 19:01 tschbc

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.

tschbc avatar Mar 10 '25 21:03 tschbc