简体   繁体   中英

Set Image.Source from photo in camera roll

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 eg "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?

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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM