KEMBAR78
[.NET 10] Implement auto-rotate images based on EXIF information & Preserve EXIF information for MediaPicker by jfversluis · Pull Request #30387 · dotnet/maui · GitHub
Skip to content

Conversation

jfversluis
Copy link
Member

@jfversluis jfversluis commented Jul 2, 2025

Description of Change

This implements the ability to auto-rotate images based on EXIF information for the MediaPicker in the Essentials library. In the MediaPickerOptions there is a new property RotateImage that can be set to true to 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 PreserveMetaData property 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

@jfversluis jfversluis added this to the .NET 10.0-preview7 milestone Jul 2, 2025
@Copilot Copilot AI review requested due to automatic review settings July 2, 2025 14:51
@jfversluis jfversluis requested a review from a team as a code owner July 2, 2025 14:51
@jfversluis jfversluis added p/0 Work that we can't release without area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info labels Jul 2, 2025
@dotnet-policy-service
Copy link
Contributor

🚨 API change(s) detected @davidortinau FYI

@dotnet dotnet deleted a comment from dotnet-policy-service bot Jul 2, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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 RotateImage property on MediaPickerOptions with XML docs and updated PublicAPI.
  • Extended ImageProcessor to 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 RotateImage feature lacks automated tests. Please add unit tests in TestCases.Shared.Tests and corresponding UI tests in TestCases.HostApp to cover the auto-rotation behavior.
		public bool RotateImage { get; set; } = false;

src/Essentials/src/MediaPicker/MediaPicker.windows.cs:100

  • The call to ProcessImageAsync is missing the input Stream argument (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.ProcessImageAsync here omits the required input Stream argument. It needs the source stream as the first parameter before the width, height, quality, filename, and rotate flag.
					options?.CompressionQuality ?? 100,

@jfversluis jfversluis moved this from Todo to Ready To Review in MAUI SDK Ongoing Jul 2, 2025
@jfversluis jfversluis changed the title [.NET 10] Implement auto-rotate images based on EXIF information for MediaPicker [.NET 10] Implement auto-rotate images based on EXIF information & Preserver EXIF information for MediaPicker Jul 3, 2025
@jfversluis jfversluis changed the title [.NET 10] Implement auto-rotate images based on EXIF information & Preserver EXIF information for MediaPicker [.NET 10] Implement auto-rotate images based on EXIF information & Preserve EXIF information for MediaPicker Jul 3, 2025
@jfversluis jfversluis requested a review from PureWeen July 3, 2025 09:47
}
catch (Exception ex)
{
System.Console.WriteLine($"Exception in RotateImageAsync: {ex}");
Copy link
Contributor

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?

Copy link
Member Author

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

@github-project-automation github-project-automation bot moved this from Ready To Review to Changes Requested in MAUI SDK Ongoing Jul 9, 2025
@jfversluis jfversluis force-pushed the net10-mediapicker-autorotate branch from 39ed162 to 5cc0e07 Compare July 18, 2025 08:34
@jfversluis jfversluis requested a review from jsuarezruiz July 18, 2025 08:35
@jfversluis jfversluis moved this from Changes Requested to Ready To Review in MAUI SDK Ongoing Jul 18, 2025
@PureWeen
Copy link
Member

  • failing tests aren't related

@PureWeen PureWeen merged commit c557c6b into net10.0 Jul 28, 2025
129 of 131 checks passed
@PureWeen PureWeen deleted the net10-mediapicker-autorotate branch July 28, 2025 20:59
@github-project-automation github-project-automation bot moved this from Ready To Review to Done in MAUI SDK Ongoing Jul 28, 2025
@PureWeen
Copy link
Member

/backport to release/10.0.1xx-preview7

@github-actions
Copy link
Contributor

Started backporting to release/10.0.1xx-preview7: https://github.com/dotnet/maui/actions/runs/16580183038

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info p/0 Work that we can't release without t/breaking 💥

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants