在Silverlight应用程序中,我保存这样的位图:
public static void SaveBitmapImageToIsolatedStorageFile(OpenReadCompletedEventArgs e, string fileName)
{
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName, FileMode.Create, isf))
{
Int64 imgLen = (Int64)e.Result.Length;
byte[] b = new byte[imgLen];
e.Result.Read(b, 0, b.Length);
isfs.Write(b, 0, b.Length);
isfs.Flush();
isfs.Close();
isf.Dispose();
}
}
}
并像这样读回来:
public static BitmapImage LoadBitmapImageFromIsolatedStorageFile(string fileName)
{
string text = String.Empty;
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isf.FileExists(fileName))
return null;
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isoStream = isoStore.OpenFile(fileName, FileMode.Open))
{
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(isoStream);
return bitmapImage; // "Catastrophic Failure: HRESULT: 0x8000FFFF (E_UNEXPECTED))"
}
}
}
}
但这总是给我一个“灾难性故障:HRESULT:0x8000FFFF (E_UNEXPECTED)) ”错误。
当我尝试从服务器读取实际上是文本文件的png 文件之前,我已经看到了这个错误,所以我认为位图没有正确保存,我在这里得到了代码。
谁能看到 BitmapImage 没有正确保存?或者为什么它会给我这个错误?
更新:
创建 BitmapImage 时,我看到写入的字节数组是 1876 字节长,它们都是 0。为什么会这样?