CommunityToolkit / Maui

The .NET MAUI Community Toolkit is a community-created library that contains .NET MAUI Extensions, Advanced UI/UX Controls, and Behaviors to help make your life as a .NET MAUI developer easier
https://learn.microsoft.com/dotnet/communitytoolkit/maui
MIT License
2.2k stars 375 forks source link

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

Open tschbc opened 1 month ago

tschbc commented 1 month ago

Is there an existing issue for this?

Did you read the "Reporting a bug" section on Contributing file?

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 commented 1 month ago

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

polincev commented 1 month ago

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