Media file picker features in .NET MAUI like in Xamarin Forms

Chinmay Dole 180 Reputation points
2024-07-15T08:47:32.7+00:00

Hi,

Is there any way to compress the image and remove the metadata option for the media picker in MAUI like it had in the below package?

https://github.com/jamesmontemagno/MediaPlugin

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,578 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 32,306 Reputation points Microsoft Vendor
    2024-07-16T09:11:50.1066667+00:00

    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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.