[英]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: 在我的Windows Phone 8.1 App中,我使用相机拍摄照片并将其保存在相机胶卷中,并将图像路径保存在一个临时对象中:
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: 在我的应用的另一页中,我想从相机胶卷中加载这张照片,并将保存的路径设置为Image对象的来源:
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"
图像的保存路径为
"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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.