Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Loading Image from disk using imageSource.FromURI

$
0
0

Hello All,

I have a question regarding imageSource for Xamarin.Forms:
I'm trying to load an image from a user's photo library (working with the iOS simulator right now). I am using Xamarin.Mobile.MediaPicker to accomplish this. I have managed to grab the URI when the user selects a photo, but setting the imageSource to this URI does not seems to work. Any thoughts?

Below is my code:

private async void btnSelectPhoto_Clicked(object sender, EventArgs e)
    {
        // Select Photo
        System.Diagnostics.Debug.WriteLine("Select Photo button pressed");

        Task<string> selectPhotoTask = DependencyService.Get<ICapturePhoto>().SelectPhoto();
        string filePath = await selectPhotoTask;
        Debug.WriteLine("Holy cow I have the filePath:{0}", filePath);

        Uri path = new Uri(filePath);

        // Set image source from selected image
        CapturedImage.Source = ImageSource.FromUri(path);       // This is the line in question
    }

The file path yields:

file:///Users/myUserName/Library/Application Support/iPhone Simulator/7.1/Applications/59352A3E-354E-4E7D-B1BB-44DDA775AA99/Documents/temp/IMG_20140821_183706.jpg

Disclaimer: I'm very new to C# so I may be confused about some basic things. I haven't however been able to find any solutions online regarding my issue. Hopefully someone here can help.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>