2
我試圖從網上保存的圖像從後臺任務的獨立存儲,但它拋出保存圖像從BG任務隔離存放
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in System.Windows.ni.dll
我使用這段代碼
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists(tempJPEG))
{
myIsolatedStorage.DeleteFile(tempJPEG);
}
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);
StreamResourceInfo sri = null;
Uri uri = new Uri(tempJPEG, UriKind.Relative);
sri = Application.GetResourceStream(uri);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.Result);
WriteableBitmap wb = new WriteableBitmap(bitmap);
// Encode WriteableBitmap object to a JPEG stream.
Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
//wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
fileStream.Close();
}
這是從應用程序運行,但不是從後臺任務運行的100%。 有關如何保存圖像的任何提示?
謝謝,但我已經設法解決這個問題,只需創建一個文件和二進制文件複製下載的圖像到新文件。至今似乎工作得很好。 – Aviatrix