Windows phone 8 WinRT:如何通过URI从图片库读取图像?
试图通过URI读取存储在图片库中的图像时,图像将永远不会显示(在图像控件中)。通过流读取相同的图像是可行的(当然假设应用程序具有声明的图片库功能)。通过URI从应用程序的数据文件夹读取图像是可行的 有人知道会出什么问题吗 以下是我(未成功)如何尝试通过URI读取图像:Windows phone 8 WinRT:如何通过URI从图片库读取图像?,windows-phone-8,windows-store-apps,Windows Phone 8,Windows Store Apps,试图通过URI读取存储在图片库中的图像时,图像将永远不会显示(在图像控件中)。通过流读取相同的图像是可行的(当然假设应用程序具有声明的图片库功能)。通过URI从应用程序的数据文件夹读取图像是可行的 有人知道会出什么问题吗 以下是我(未成功)如何尝试通过URI读取图像: var imageFile = (await KnownFolders.PicturesLibrary.GetFilesAsync()).FirstOrDefault(); string imagePath = imageFile
var imageFile = (await KnownFolders.PicturesLibrary.GetFilesAsync()).FirstOrDefault();
string imagePath = imageFile.Path;
Uri uriSource = new Uri(imagePath);
var bitmap = new BitmapImage(uriSource);
this.Image.Source = bitmap;
以下是我如何通过流成功读取同一图像:
var imageFile = (await KnownFolders.PicturesLibrary.GetFilesAsync()).FirstOrDefault();
BitmapImage bitmap;
using (var stream = await imageFile.OpenReadAsync())
{
bitmap = new BitmapImage();
await bitmap.SetSourceAsync(stream);
}
this.Image.Source = bitmap;
我需要通过URI读取图像,因为这是读取图像的最快方式,本质上是异步的,与数据绑定完美结合。图片库没有URI。您需要获取存储文件并将其流式传输进来
您使用的文件URI无效,因为应用程序无法直接访问PicturesLibrary,因此无法通过路径引用其中的项目。StorageFile对象提供对应用程序本机无权访问的位置的代理访问。如果我想将
MediaElement
或Image
的源绑定到例如照片库中的文件,我如何在没有代码的情况下执行?