0

我正在尝试从 IsolatedStorage 中保存图像。我收到错误消息:“Operation not allowed on IsolatedStorageFileStream。”。我的代码如下所示。我该如何克服这个问题?

  public HomePage()
        {
            InitializeComponent();
            // Create a filename for JPEG file in isolated storage.
            String tempJPEG = "/Images/homescreenmap.png";

            // Create virtual store and file stream. Check for duplicate tempJPEG files.
            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(sri.Stream);
                WriteableBitmap wb = new WriteableBitmap(bitmap);

                // Encode WriteableBitmap object to a JPEG stream.
                Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);

                //wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
                fileStream.Close();
            }


        }
4

1 回答 1

0

隔离存储异常意味着它找不到您设置的位置的路径,在您的情况下,这是文件夹图像。只需在创建文件之前添加以下代码:

if (!myIsolatedStorage.DirectoryExists("Images"))
{
    myIsolatedStorage.CreateDirectory("Images");
}
于 2012-08-21T05:27:20.323 回答