我对 FileOpenPicker (ModernUI xaml/c#) 有问题,因为如果从网络上挑选一些图片,它会返回“StorageFile”而没有错误,但是当我尝试使用 OpenAsync 打开它时,系统会抛出 FileNotFoundException。特别是我注意到,如果从 facebook 获取旧照片,这种情况总是会发生。
使用SDK Sample app "XAML images sample"很容易重现该问题。只需启动应用程序并从“Facebook”获取一些图片,并确保获取一些旧图片,因为我注意到最新的图片可以正常打开。
更具体地说,请找到实际抛出该异常的代码的和平:
// Open a stream for the selected file
StorageFile file = await open.PickSingleFileAsync();
// Ensure a file was selected
if (file != null)
{
// Ensure the stream is disposed once the image is loaded
// !!! Here exception is thrown if you pickup some old file from facebook !!!
using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
// Set the image source to the selected bitmap
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.DecodePixelHeight = decodePixelHeight;
bitmapImage.DecodePixelWidth = decodePixelWidth;
await bitmapImage.SetSourceAsync(fileStream);
Scenario2Image.Source = bitmapImage;
}
}
提前感谢您的建议和帮助
亲切的问候
MG