将图像保存到隔离存储中

时间:2011-06-16 14:37:04

标签: windows-phone-7 isolatedstorage

  

可能重复:
  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); 

 } 
}

1 个答案:

答案 0 :(得分: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();
    }
}