question

WeiWen-3421 avatar image
0 Votes"
WeiWen-3421 asked JarvanZhang-MSFT edited

Using ImageSource.FromStream() as a Source for Image does not work on iOS

I used MediaGallery.PickAsync() to pick multiple photos. I then use its OpenReadAsync() to get stream to set as Source of Image. It works fine on Android. However, when it comes to iOS, I got the error "Errors in file generation". I think I will need to either get the full path of the picked image files or use some other means to create files from the stream. How can I achieve this?

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

WeiWen-3421 avatar image
0 Votes"
WeiWen-3421 answered JarvanZhang-MSFT edited

That seems to be an issue only for emulators. It works fine on real devices.

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, WeiWen-3421. Based on my test, there is nothing wrong with the ImageSource.FromStream() code. It works as expected on iphone emulators when using Essential.MediaPicker to picker the photo and set source for an image.

private async void Button_Clicked(object sender, EventArgs e)
{
    var file = await MediaPicker.PickPhotoAsync();
    var stream = await file.OpenReadAsync();

    img.Source = ImageSource.FromStream(() => { return stream; });
}

Please test the code on your side to check the issue. If the problem only occurs with the third party library code: 'MediaGallery.PickAsync', please report the issue to the related github repo.

0 Votes 0 ·

@JarvanZhang-MSFT I noticed you used MediaPicker. What I used is MediaGallery to pick multiple photos. As I said, this exception only occurs on emulator. It works fine on real devices. I will report to bug on GitHub. To show I did get an exception, I attached a screenshot of the exception.

0 Votes 0 ·

Thanks for sharing the screenshot of the exception. Here is the github repo about the package: https://github.com/dimonovdd/Xamarin.MediaGallery/issues

0 Votes 0 ·