-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[.NET 10] Implement image compression & MaximumWidth/MaximumHeight for MediaPicker #30027
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
0a47332
to
dc4afe5
Compare
373d527
to
9e0861a
Compare
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 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
, andMaximumHeight
toMediaPickerOptions
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); |
Copilot
AI
Jun 20, 2025
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.
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.
Failing test is unrelated |
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 theMediaPickerOptions
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
andMaximumHeight
. 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