我想显示通过结合存储在StorageFile图片内容的图片,但不管我试图做到这一点似乎并没有工作。显示存储在存储文件中metroapp
这里有两种解决方案我已经测试:
string img =(await CompetencesFolder.GetFileAsync(FormatImageNameToFileName(imageName))).Path;
然后通过结合返回到源物业所获得的路径(一个完整的绝对路径文件),并且:
BitmapImage img = await LoadImage(await CompetencesFolder.GetFileAsync(FormatImageNameToFileName(imageName)));
private static async Task<BitmapImage> LoadImage(StorageFile file)
{
BitmapImage bitmapImage = new BitmapImage();
FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read);
bitmapImage.SetSource(stream);
return bitmapImage;
}
稍后将最终的bitmapImage返回到绑定属性。
这些方法没有工作..
千万人有一个想法?
编辑:FIX
下面是解决该问题的代码:
BitmapImage img = new BitmapImage() { UriSource = new Uri(LOCAL_REPOSITORY.Path + "/Assets/gfx/cards/" + FormatImageNameToFileName(imageName) + ".jpg", UriKind.RelativeOrAbsolute) };
我做了2个样品的混合上面:我创造了我的BitmapImage从图片的绝对URI (LOCAL_REPOSITORY包含对本地存储的引用:ApplicationData.Current.LocalFolder
)
我仍然无法确定为什么其他两种方式失败:我通常将图像直接绑定到Uri,字符串或BitmapImage的,和它的作品..
你什么错误? – 2013-02-14 21:25:06
我没有收到任何信息:图片没有被显示,没有发生崩溃,也没有提出错误。 我解决了这个问题(请参阅编辑),但我仍然无法确定为什么其他两个样本不起作用。 – 2013-02-14 21:33:26
图片是否位于其他样本的本地文件夹中?商店应用程序没有对文件系统的任意访问权限。 – 2013-02-14 21:40:11