将图像保存到隔离存储中。

3

可能是重复问题:
在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); 

 } 
}

请查看以下链接:http://www.windowsphonegeek.com/tips/All-about-WP7-Isolated-Storage---Read-and-Save-XML-files-using-XmlWriter - Nair
能否提供一下你目前的代码?这样会更有帮助。 - lhan
1
你应该将代码编辑到问题中。这样你就可以正确地格式化它,使其更容易阅读。 - ChrisF
1个回答

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();
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接