-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[.NET 10] Implement auto-rotate images based on EXIF information & Preserve EXIF information for MediaPicker #30387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
🚨 API change(s) detected @davidortinau FYI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for auto-rotating images based on EXIF orientation in MediaPicker by introducing a RotateImage option and integrating rotation processing across all platforms.
- Exposed a new
RotateImageproperty onMediaPickerOptionswith XML docs and updated PublicAPI. - Extended
ImageProcessorto handle EXIF rotation and wired it into each platform’s photo pick/capture flows. - Updated sample app ViewModel and XAML to allow toggling the new auto-rotate feature.
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Essentials/src/PublicAPI/*/PublicAPI.Unshipped.txt | Added RotateImage.get/set to PublicAPI |
| src/Essentials/src/MediaPicker/MediaPicker.shared.cs | Defined RotateImage property and docs |
| src/Essentials/src/MediaPicker/MediaPicker.windows.cs | Injected rotation logic before compression |
| src/Essentials/src/MediaPicker/MediaPicker.ios.cs | Added rotation steps in picker result handling |
| src/Essentials/src/MediaPicker/MediaPicker.android.cs | Added rotation in capture and pick flows |
| src/Essentials/src/MediaPicker/ImageProcessor.*.cs | Implemented RotateImageAsync for each TFM |
| src/Essentials/samples/Samples/ViewModel/MediaPickerViewModel.cs | Added PickerRotateImage bindable property |
| src/Essentials/samples/Samples/View/MediaPickerPage.xaml | UI for toggling auto-rotate |
Comments suppressed due to low confidence (3)
src/Essentials/src/MediaPicker/MediaPicker.shared.cs:216
- The new
RotateImagefeature lacks automated tests. Please add unit tests inTestCases.Shared.Testsand corresponding UI tests inTestCases.HostAppto cover the auto-rotation behavior.
public bool RotateImage { get; set; } = false;
src/Essentials/src/MediaPicker/MediaPicker.windows.cs:100
- The call to
ProcessImageAsyncis missing the inputStreamargument (it currently only passes width, height, quality, filename, and rotate flag). You need to pass the source stream as the first parameter to match the method signature.
var processedStream = await ImageProcessor.ProcessImageAsync(
src/Essentials/src/MediaPicker/MediaPicker.android.cs:363
- Similar to Windows, the call to
ImageProcessor.ProcessImageAsynchere omits the required inputStreamargument. It needs the source stream as the first parameter before the width, height, quality, filename, and rotate flag.
options?.CompressionQuality ?? 100,
| } | ||
| catch (Exception ex) | ||
| { | ||
| System.Console.WriteLine($"Exception in RotateImageAsync: {ex}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use ILogger here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets do this later as a bigger effort to do this everywhere the correct way
39ed162 to
5cc0e07
Compare
|
|
/backport to release/10.0.1xx-preview7 |
|
Started backporting to release/10.0.1xx-preview7: https://github.com/dotnet/maui/actions/runs/16580183038 |
Description of Change
This implements the ability to auto-rotate images based on EXIF information for the MediaPicker in the Essentials library. In the
MediaPickerOptionsthere is a new propertyRotateImagethat can be set totrueto enable auto-rotation of images based on the EXIF information of the image, if available. If its set to false, it will return the image as-is.Additionally, the
PreserveMetaDataproperty has been added to control whether to preserve the metadata of the image when operations (rotate, resize, etc.) is being done on it.How to test
There are a couple of funny things in here if you look at the code. For iOS it will always seem to return UP and for Android I do setRotation(0) always. Which seems weird, but in fact its the right thing to do. This actually means that we will be using the orientation that is in the EXIF information.
The easiest way to functionally test this is to get a bunch of test images (use a search engine to find "EXIF test images"), load those on the device and start the sample app. This link will then be helpful to understand the different rotations: https://sirv.com/help/articles/rotate-photos-to-be-upright/
Issues Fixed
Fixes #29083