[.NET 10] Implement image compression & MaximumWidth/MaximumHeight for MediaPicker#30027
Merged
jfversluis merged 25 commits intonet10.0from Jun 23, 2025
Merged
[.NET 10] Implement image compression & MaximumWidth/MaximumHeight for MediaPicker#30027jfversluis merged 25 commits intonet10.0from
jfversluis merged 25 commits intonet10.0from
Conversation
0a47332 to
dc4afe5
Compare
jsuarezruiz
reviewed
Jun 17, 2025
373d527 to
9e0861a
Compare
Contributor
There was a problem hiding this comment.
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, andMaximumHeighttoMediaPickerOptionsand the public API. - Implement cross-platform resizing/compression using a new
ImageProcessorhelper 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
Essentialsnamespace 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); |
There was a problem hiding this comment.
The hard-coded DPI value 96 is a magic number. Consider retrieving the system or device DPI dynamically or documenting why 96 is chosen.
Member
Author
|
Failing test is unrelated |
StephaneDelcroix
approved these changes
Jun 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
CompressionQualityproperty in theMediaPickerOptionsobject.Additionally, this PR introduces a way to limit the size of the image that is returned by influencing the dimensions. On the
MediaPickerOptionsobject, two properties were added to control the size of the image:MaximumWidthandMaximumHeight. 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