WIndow 8商店应用程序自动从本地加载图像
本文关键字:加载 图像 应用程序 WIndow | 更新日期: 2023-09-27 18:33:57
我使用相机捕获照片并将其保存到本地,然后单击后退按钮返回主页,我希望捕获的照片显示在我的主页中。我在主页中使用以下代码:
MainPage.xaml.cs:
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
var parameter = e.Parameter as StorageFile;
if (parameter != null)
{
Uri uri = new Uri("CapturedImage.jpeg", UriKind.RelativeOrAbsolute);
finalImage.Source = new BitmapImage(uri);
}
}
错误消息是"系统中发生类型为'System.UriFormatException'的异常.dll但未在用户代码中处理"。我该怎么解决?谢谢
试试这个
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
var parameter = e.Parameter as StorageFile;
if (parameter != null)
{
using (var strm = await parameter.OpenReadAsync())
{
var bmp = new BitmapImage();
bmp.SetSource(strm);
finalImage.Source = bmp;
}
}
}
Uri
仅适用于这些方案。
如果文件位于本地、漫游或临时目录中,请使用
Uri
作为ms-appdata:///local/CapturedImage.jpeg
或ms-appdata:///roaming/CapturedImage.jpeg
如果文件是包的一部分,请使用
Uri
作为ms-appx:///YOUR_FOLDER/CapturedImage.jpeg