C# 在windows phone中保存图像

C# 在windows phone中保存图像,c#,windows-phone-7,isolatedstorage,C#,Windows Phone 7,Isolatedstorage,每当我试图保存文件时,都会出现此错误- 1. System.IO.IsolatedStorage.IsolatedStorageException was unhandled Message=Operation not permitted on IsolatedStorageFileStream. StackTrace: at System.IO.IsolatedStorage.IsolatedStorageFileSt

每当我试图保存文件时,都会出现此错误-

   1. System.IO.IsolatedStorage.IsolatedStorageException was unhandled  
        Message=Operation not permitted on IsolatedStorageFileStream.  
        StackTrace:
               at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String
        path, FileMode mode, FileAccess access, FileShare share, Int32
        bufferSize, IsolatedStorageFile isf)
               at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String
        path, FileMode mode, FileAccess access, IsolatedStorageFile isf)
               at System.IO.IsolatedStorage.IsolatedStorageFile.OpenFile(String path,
        FileMode mode, FileAccess access)
               at PaintBrush.Save.savepic()
               at PaintBrush.Save..ctor()
               at PaintBrush.MainPage.click_btnSave(Object sender, RoutedEventArgs e)
               at System.Windows.Controls.Primitives.ButtonBase.OnClick()
               at System.Windows.Controls.Button.OnClick()
               at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs
        e)
               at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl,
        EventArgs e)
               at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32
        actualArgsTypeIndex, String eventName)
我正在尝试保存一个图像。我浏览过谷歌,发现他们说要在写之前关闭文件流,但我没有得到,因为我在写之前关闭文件流时也遇到了同样的错误。这是我的密码--


以下是我的片段,可能会对您有所帮助

我认为你的问题在于你的
OpenFile
方法

 // Create a filename for JPEG file in isolated storage.
 String tempJPEG = "logo.jpg";
 // Create virtual store and file stream.
 using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
 {

     IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);

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

以下是我的片段,可能会对您有所帮助

我认为你的问题在于你的
OpenFile
方法

 // Create a filename for JPEG file in isolated storage.
 String tempJPEG = "logo.jpg";
 // Create virtual store and file stream.
 using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
 {

     IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);

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

您是否尝试过使用
FileMode.Create
而不是
FileMode.Open
?我尝试过此方法,但没有结果。您是否尝试过使用
FileMode.Create
而不是
FileMode.Open
?我尝试过此方法,但没有结果。我尝试过此方法,但遇到相同的问题。我是否需要更改app.xaml或manifest中的任何内容才能访问独立存储?@Developer我找到了一个教程,可以帮助你:并且没有必要更改app.xaml或manifest.xaml中的任何内容。顺便说一句,你一开始就声明使用隔离存储了吗?我试过了,但遇到了同样的问题。我是否需要更改app.xaml或manifest中的任何内容才能访问独立存储?@Developer我找到了一个教程,可以帮助你:并且没有必要更改app.xaml或manifest.xaml中的任何内容。顺便说一句,你一开始就声明使用独立存储了吗?请添加一些解释请添加一些解释
MessageBar.Text = "Uploading to SkyDrive";
IsolatedStorageFileStream fileStream = null;
//string strSaveName = "images.jpg";               
try
{
   using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
   {
      fileStream = store.OpenFile("contact.txt", FileMode.Open, FileAccess.Read);
   }
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
client.UploadAsync("me/SkyDrive", "contact.txt", fileStream, OverwriteOption.Overwrite);