Hello,
You can select the photo from gallery by calling the MediaPicker.PickPhotoAsync()
method and resize the image by calling Microsoft.Maui.Graphics.IImage
API.
For more details, please refer to
Media picker for photos and videos - .NET MAUI | Microsoft Learn
Images - .NET MAUI | Microsoft Learn
and the following code:
private async void OnCounterClicked(object sender, EventArgs e)
{
FileResult result = await MediaPicker.PickPhotoAsync();
if (result != null)
{
var stream = await result.OpenReadAsync();
ImageSource image = ImageSource.FromStream(() => stream);
MyImage.Source = image; // display the image that didn't downsize
var stream1 = await result.OpenReadAsync();
var image1 = PlatformImage.FromStream(stream1);
if (image1 != null)
{
var newImage = image1.Downsize(100, true);// downsize
byte[] downsizeimage = newImage.AsBytes();
var imageMemaryStream = new MemoryStream(downsizeimage);
ImageSource source = ImageSource.FromStream(() => imageMemaryStream);
ShowImage.Source = source;
}
}
}
Update
Is there any way to remove all the metadata from the image?
I got it. And I check the source code in MediaPlugin, this part is not included in MAUI. And there is a known issue reported on MAUI GitHub- Media Picker CameraOptions · Issue #23596 · dotnet/maui (github.com), please follow the progress.
Also, I understand that you want to remove the metadata on iOS and Android platform. The only way is to call the native iOS/ Android platform codes like the source code that I mentioned.
See .NET MAUI invoking platform code - .NET MAUI | Microsoft Learn
Best Regards, Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.