1
在Silverlight的應用程序,我節省了位圖這樣的:爲什麼Silverlight代碼在從IsolatedStorage中讀取BitmapImage時會發生「災難性故障」?
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();
}
}
}
和閱讀它背出來是這樣的:
但總是給我一個「災難性故障:HRESULT:0x8000FFFF(E_UNEXPECTED))「錯誤。
我已經看到了,當我試圖讀取png文件關閉這實際上是一個文本文件服務器之前這個錯誤,所以我假設位圖沒有被正確保存,我got the code here。
任何人都可以看到如何正確保存BitmapImage?或者爲什麼它會給我這個錯誤?
更新:
當創建的BitmapImage,我看到的是被寫入的字節數組是1876年字節長,他們都爲0,爲什麼會是這樣?
SetSource將從流中讀取(e.Result),所以流中的位置將會改變,但長度不會改變。我不確定是否允許您在結果流上查找,但是您可以使用MemoryStream作爲緩衝區並回到開始再次使用數據。 – toby 2011-07-08 15:27:28