2011-06-16 62 views
3

可能重复:
store image into isolated storage in windows phone 7保存图片到隔离存放

我使用Visual Studio/Expression Blend中创建为我的Windows Phone 7的应用程序,用户应该能够选择一张他/她想要编辑的图片,编辑完成后,用户可以点击“保存”按钮,特定的编辑图像将被保存在独立的存储器中。但是我无法通过按钮点击事件将图像保存到独立存储。

有没有人有如何实现这个代码示例?谢谢!

我对按钮的代码:

using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication()) 

{ 

var bi = new BitmapImage(); bi.SetSource(pic); 

var wb = new WriteableBitmap(lion.jpg,lion.jpg.RenderTransform); 

using (var isoFileStream = isoStore.CreateFile("somepic.jpg")) 

{ 

var width = wb.PixelWidth; 

var height = wb.PixelHeight; 

Extensions.SaveJpeg(wb, isoFileStream, width, height, 0, 100); 

} 
} 
+0

有一个看看下面的链接http://www.windowsphonegeek.com/tips/All-about-WP7-Isolated-Storage---Read-and-Save-XML-files-using-XmlWriter – Nair 2011-06-16 14:45:15

+0

这将有助于看到你的代码到目前为止? – lhan 2011-06-16 14:45:23

+1

您应该[编辑](http://stackoverflow.com/posts/6373702/edit)代码到问题中。您可以正确格式化,以便阅读起来更容易。 – ChrisF 2011-06-16 14:58:12

回答

7

要从PhotoChooserTask保存到IsolatedStorage的图像,使用(在任务回调e对象持有的流):

public static void SaveImage(Stream imageStream, string fileName, int orientation, int quality) 
{ 
    using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) 
    { 
     if (isolatedStorage.FileExists(fileName)) 
      isolatedStorage.DeleteFile(fileName); 

     IsolatedStorageFileStream fileStream = isolatedStorage.CreateFile(fileName); 
     BitmapImage bitmap = new BitmapImage(); 
     bitmap.SetSource(imageStream); 

     WriteableBitmap wb = new WriteableBitmap(bitmap); 
     wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, orientation, quality); 
     fileStream.Close(); 
    } 
}