2013-01-02 22 views
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%。 有關如何保存圖像的任何提示?

回答