Set Image.Source from photo in camera roll

804 views Asked by At

In my Windows Phone 8.1 App i take a photo with the camera and save this in the camera roll and save the image path in a temporary object:

var picture = library.SavePictureToCameraRoll(fileName, e.ImageStream);
geophoto.ImagePath = picture.GetPath();

In another page of my app i want to load this photo from the camera roll and set the saved path as the source of an Image object:

Uri uri = new Uri(App.Current.Geophoto.ImagePath, UriKind.Absolute);
ImageSource imgSource = new BitmapImage(uri);
this.ShutterImage.Source = imgSource; 

The saved path of the image is e.g. "file:///C:/Data/Users/Public/Pictures/Camera Roll/201506191442443805.jpg"

In runtime the image goes blank when i try to set a new source. Is there something wrong with the path or with the code?

1

There are 1 answers

0
ManfredP On

I figured out that i have no direct access to camera roll through the path. So i solved my problem with the following code:

    private BitmapImage GetThumbnailFromCameraRoll(string path)
    {
        MediaLibrary mediaLibrary = new MediaLibrary();
        var pictures = mediaLibrary.Pictures;
        foreach (var picture in pictures)
        {
            var camerarollPath = picture.GetPath();
            if (camerarollPath == path)
            {
                BitmapImage image = new BitmapImage();
                image.SetSource(picture.GetThumbnail());
                return image;
            }
        }

        return null;
    }