KEMBAR78
[.NET 10] Implement image compression & MaximumWidth/MaximumHeight for MediaPicker by jfversluis · Pull Request #30027 · dotnet/maui · GitHub
Skip to content

Conversation

jfversluis
Copy link
Member

@jfversluis jfversluis commented Jun 17, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

This PR introduces image compression for MediaPicker. This works for images only when picked from the gallery as well as when captured through the camera. The quality of the image can be controlled by setting the newly introduced CompressionQuality property in the MediaPickerOptions object.

Additionally, this PR introduces a way to limit the size of the image that is returned by influencing the dimensions. On the MediaPickerOptions object, two properties were added to control the size of the image: MaximumWidth and MaximumHeight. Based on the values, the picked/captured image will be resized to fit within the specified dimensions while maintaining the aspect ratio.

As a bonus the Essentials Sample looks a bit nicer and is updated to play with all these new features.

Issues Fixed

Fixes #29080
Fixes #29081

@dotnet dotnet deleted a comment from dotnet-policy-service bot Jun 17, 2025
@dotnet dotnet deleted a comment from dotnet-policy-service bot Jun 19, 2025
@jfversluis jfversluis changed the title [.NET 10] Implement image compression for MediaPicker [.NET 10] Implement image compression & MaximumWidth/MaximumHeight for MediaPicker Jun 19, 2025
@jfversluis jfversluis added the p/0 Work that we can't release without label Jun 19, 2025
@jfversluis jfversluis force-pushed the ne10-mediapicker-compression branch from 373d527 to 9e0861a Compare June 20, 2025 19:02
@jfversluis jfversluis marked this pull request as ready for review June 20, 2025 19:03
@jfversluis jfversluis requested a review from a team as a code owner June 20, 2025 19:03
@jfversluis jfversluis requested review from Aguilex, PureWeen, Copilot and tj-devel709 and removed request for Aguilex June 20, 2025 19:04
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 image compression and maximum dimension control to the MediaPicker APIs across platforms, and updates the sample app to demonstrate and configure these new features.

  • Introduce CompressionQuality, MaximumWidth, and MaximumHeight to MediaPickerOptions and the public API.
  • Implement cross-platform resizing/compression using a new ImageProcessor helper and platform‐specific integrations (Windows, iOS, Android).
  • Enhance the Essentials sample app’s ViewModel and XAML to configure compression/resize options and display image metadata.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Graphics/.../PlatformImage.cs Implemented Downsize(maxWidth, maxHeight) with Win2D rendering
src/Essentials/.../PublicAPI.Unshipped.txt Exposed new CompressionQuality, MaximumWidth, MaximumHeight
src/Essentials/.../MediaPicker.windows.cs Apply processing in Pick*Async methods and added ProcessedImageFileResult
src/Essentials/.../MediaPicker.shared.cs Added XML docs for Pick*Async, duplicated method signatures
src/Essentials/.../MediaPicker.ios.cs Integrated image processing in iOS pick/capture flows
src/Essentials/.../MediaPicker.android.cs Integrated image processing in Android pick/capture flows
src/Essentials/.../ImageProcessor.shared.cs New ImageProcessor for unified resizing/compression logic
src/Essentials/samples/.../MediaPickerViewModel.cs Updated sample VM with compression/resize properties and metadata extraction
src/Essentials/samples/.../MediaPickerPage.xaml Redesigned sample UI to configure settings and show image info
Comments suppressed due to low confidence (2)

src/Essentials/src/MediaPicker/ImageProcessor.shared.cs:1

  • Introduce unit tests for ImageProcessor.ProcessImageAsync, resizing logic, and format decisions to ensure cross-platform consistency and catch regression.
using System;

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

  • [nitpick] Importing the Essentials namespace inside its own assembly may be confusing. Consider qualifying or consolidating helper classes to avoid circular dependency concerns.
			}

var newHeight = (int)(Height * scale);

// Create a new render target with the scaled dimensions
var newRenderTarget = new CanvasRenderTarget(_creator, newWidth, newHeight, 96);
Copy link

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hard-coded DPI value 96 is a magic number. Consider retrieving the system or device DPI dynamically or documenting why 96 is chosen.

Copilot uses AI. Check for mistakes.

@jfversluis
Copy link
Member Author

Failing test is unrelated

@jfversluis jfversluis merged commit e3be964 into net10.0 Jun 23, 2025
127 of 129 checks passed
@jfversluis jfversluis deleted the ne10-mediapicker-compression branch June 23, 2025 14:31
@github-actions github-actions bot locked and limited conversation to collaborators Jul 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants