[英]Set Image.Source from photo in camera roll
在我的Windows Phone 8.1 App中,我使用相机拍摄照片并将其保存在相机胶卷中,并将图像路径保存在一个临时对象中:
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"
在运行时,当我尝试设置新来源时,图像变为空白。 路径或代码有问题吗?
我发现我无法直接访问该路径中的相机胶卷。 所以我用下面的代码解决了我的问题:
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.