【发布时间】:2015-05-16 08:08:14
【问题描述】:
每当我尝试从本地文件中检索图像时,上述异常发生在await bitmapImage.SetSourceAsync(fileStream); 行。
这是我用于存储和检索图像文件的方法。
public async Task<BitmapImage> RetrieveImageFromFile(String fileName)
{
try
{
StorageFile localFile = await _storageFolder.GetFileAsync(fileName + "Img");
BitmapImage bitmapImage = new BitmapImage();
using (IRandomAccessStream fileStream = await localFile.OpenAsync(FileAccessMode.Read))
{
await bitmapImage.SetSourceAsync(fileStream);
}
return bitmapImage;
}
catch(Exception e)
{
return null;
}
}
public async void WriteImageToFile(string fileName, IRandomAccessStreamWithContentType stream )
{
StorageFile file = await _storageFolder.CreateFileAsync(fileName + "Img", CreationCollisionOption.ReplaceExisting);
Stream streamToSave = stream.AsStreamForWrite();
using (Stream fileStram = await file.OpenStreamForWriteAsync())
{
streamToSave.CopyTo(fileStram);
}
}
WriteImageToFile 方法的输入流是从contact.Thumbnail.OpenReadAsync() 方法中获取的
有什么帮助吗?
【问题讨论】:
-
我提出了同样的问题...您找到解决方案了吗?
-
希望您现在已经解决了这个问题,但 0x88982f50 错误通常与无法正确读取/解码图像文件有关。验证您的文件格式是否正确。 (谷歌 88982f50 可以看到几十个可能相关的修复程序,都与图像文件 I/O 相关。)这也是我的问题...错误文件。
-
@sraboy 谢谢,你为我节省了一天:) 0 字节大小或格式错误的错误文件。我们应该始终检查流是否成功创建
-
在 Windows UWP 上使用 ImageLib 时也会出现此问题。如何检查流是否成功创建?我猜只是检查它是否不为空,并捕获潜在的异常。
-
@sraboy 很高兴成为第一个为您的答案投票的人。
标签: c# stream windows-runtime windows-phone-8.1 storagefile