Hello,
Welcome to our Microsoft Q&A platform!
Here is a sample which is implemented by Xamarin.Essentials: Media Picker.
You can refer to the following code:
async void Button_Clicked(System.Object sender, System.EventArgs e)
{
var result = await MediaPicker.PickPhotoAsync(new MediaPickerOptions
{
Title = "Please pick a photo"
});
if (result != null)
{
var stream = await result.OpenReadAsync();
resultImage.Source = ImageSource.FromStream(() => stream);
}
}
The xaml code:
<Image x:Name="resultImage" />
And you can check the full sample here: https://github.com/jfversluis/XFEMediaPickerSample
Update:
We just need to use the following code, the rest can be deleted(I tested on my side, it works properly.):
async Task LoadPhotoAsync(FileResult photo)
{
// canceled
if (photo == null)
{
PhotoPath = null;
return;
}
// save the file into local storage
var newFile = photo.FullPath;
var stream = await photo.OpenReadAsync();
MyImage.Source = ImageSource.FromStream(() => stream);
}
}
Best Regards,
Jessie Zhang
---
If the response is helpful, please click "Accept Answer" and upvote it.
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.