Search code examples
iosimageuiimagensurlxamarin.forms

display images from iOS gallery


Through a platform-dependent service I've managed to fetch the NSUrl of an image from one of the galleries on the device. It looks like this: "assets-library://asset/asset.JPG?id=01202427-4916-4F8F-99AA-D38D88181558&ext=JPG". How can I use it to set the source of an Image view in the Xamarin.Forms shared project?


Solution

  • I solved by using a stream:

    var s = originalImage.AsPNG ().AsStream ();
    SharedView.SetImageStream(s);
    

    In the PCL side:

    public void SetImageStream(System.IO.Stream s)
    {
        theImageView.Source = ImageSource.FromStream(() => s);
    }