[英]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.