0

在我的 Windows Phone 8.1 应用程序中,我用相机拍照并将其保存在相机胶卷中,并将图像路径保存在临时对象中:

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

在我的应用程序的另一个页面中,我想从相机胶卷中加载这张照片并将保存的路径设置为 Image 对象的来源:

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

图像的保存路径例如"file:///C:/Data/Users/Public/Pictures/Camera Roll/201506191442443805.jpg"

在运行时,当我尝试设置新源时,图像变为空白。路径或代码有问题吗?

4

1 回答 1

0

我发现我无法通过路径直接访问相机胶卷。所以我用下面的代码解决了我的问题:

    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;
    }
于 2015-07-01T09:28:16.723 回答