将图像保存到独立存储中 [英] save image into isolated storage

查看:47
本文介绍了将图像保存到独立存储中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
将图像存储到 Windows Phone 7 中的独立存储中

我正在使用 Visual Studio/Expression Blend 为 Windows Phone 7 创建我的应用程序.用户应该能够选择他/她想要编辑的图片,编辑后,用户可以单击保存"按钮,然后特定编辑的图像将保存在独立存储中.但是我无法通过按钮单击事件将图像保存到独立存储.

I am using Visual Studio/Expression Blend to create my app for windows phone 7. The user should be able to select a picture that he/she wants to edit and after editing, the user can click a "save" button and the specific edited image will be saved in isolated storage. But I'm having trouble saving the image to Isolated Storage from the button click event.

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

Does anyone have a code example of how this can be achieved? Thanks!

我的按钮代码:

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

 } 
}

推荐答案

要将图像从 PhotoChooserTask 保存到 IndependentStorage,请使用此(任务回调中的 e 对象保存流):

To save an image to IsolatedStorage from a PhotoChooserTask, use this (the e object in the task callback holds the stream):

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

这篇关于将图像保存到独立存储中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆