店面形象到Windows Phone 7的隔离存放 [英] store image into isolated storage in windows phone 7

查看:114
本文介绍了店面形象到Windows Phone 7的隔离存放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我使用Visual Studio / Expression Blend中做我的应用程序。其作品中,用户可以选择他/她想要编辑的图片和编辑用户后,刚点击保存按钮,编辑后的图像将在独立存储来保存,但是我就是无法指挥Save按钮保存图像到独立的存储如此希望有人能帮助我与它的一些示例代码感谢很多提前。



我试着用下面的代码,但是当我按下保存按钮有一个空引用错误。我的想法是,当你按下保存,应用程序不知道哪个图像保存到独立存储和真的不知道我的想法是正确的。任何人都可以请帮我这。非常感谢。

 私人无效btnSave_Click(对象发件人,RoutedEventArgs E)
{
字符串tempJPEG = TempJPEG;

变种的MyStore = IsolatedStorageFile.GetUserStoreForApplication();
如果(myStore.FileExists(tempJPEG))
{
myStore.DeleteFile(tempJPEG);
}

IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempJPEG);

乌里URI =新的URI(TestImage.jpg,UriKind.Relative);
StreamResourceInfo斯里兰卡= Application.GetResourceStream(URI);

的BitmapImage位=新的BitmapImage();
bitmap.CreateOptions = BitmapCreateOptions.None;
bitmap.SetSource(sri.Stream);
WriteableBitmap的WB =新的WriteableBitmap的(位图);

Extensions.SaveJpeg(WB,myFileStream,wb.PixelWidth,wb.PixelHeight,0,85);
myFileStream.Close();


解决方案

这是代码的工作版本

 私人无效saveButtonClick(对象发件人,RoutedEventArgs E)
{

{
使用(VAR ISF = IsolatedStorageFile.GetUserStoreForApplication())
{
如果(isf.FileExists(myImage.jpg这个参数))
isf.DeleteFile(myImage.jpg这个参数);使用
(VAR ISFS = isf.CreateFile(myImage.jpg这个参数))
{
变种BMP =新的WriteableBitmap的(myImageElement,
myImageElement.RenderTransform);
bmp.SaveJpeg(ISFS,bmp.PixelWidth,bmp.PixelHeight,0,100);
}
}
}
赶上(例外EXC)
{
MessageBox.Show(exc.Message);
}
}

下面 myImageElement 是在其中显示图像的图像元素。


Basically I am using Visual Studio/Expression Blend to do my app. Its works as in the user can select the picture that he/she wants to edit and after editing the user just had to click the save button and the edited image will be save in isolated storage but I just could not command the save button to save the image into the isolated storage so hope someone will help me with it with some sample codes thanks a lot in advance.

I tried with the code below but when I press the save button there's a null reference error. My thinking is that when you press save, the app does not know which image to save into the isolated storage and not really sure my thinking is right. Can anyone please help me with this. Thanks a lot.

private void btnSave_Click(object sender, RoutedEventArgs e)
{
    String tempJPEG = "TempJPEG";

    var myStore = IsolatedStorageFile.GetUserStoreForApplication();
    if (myStore.FileExists(tempJPEG))
    {
        myStore.DeleteFile(tempJPEG);
    }

    IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempJPEG);

    Uri uri = new Uri("TestImage.jpg", UriKind.Relative);
    StreamResourceInfo sri = Application.GetResourceStream(uri);

    BitmapImage bitmap = new BitmapImage();
    bitmap.CreateOptions = BitmapCreateOptions.None; 
    bitmap.SetSource(sri.Stream);
    WriteableBitmap wb = new WriteableBitmap(bitmap);

    Extensions.SaveJpeg(wb, myFileStream, wb.PixelWidth, wb.PixelHeight, 0, 85);
    myFileStream.Close();

解决方案

This is the working version of the code

private void saveButtonClick(object sender, RoutedEventArgs e)
{
    try
    {
        using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (isf.FileExists("myImage.jpg"))
                isf.DeleteFile("myImage.jpg");
            using (var isfs = isf.CreateFile("myImage.jpg"))
            {
                var bmp = new WriteableBitmap(myImageElement,
                                myImageElement.RenderTransform);
                bmp.SaveJpeg(isfs, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
            }
        }
    }
    catch (Exception exc)
    {
        MessageBox.Show(exc.Message);
    }
}

Here myImageElement is the Image Element in which you display the image.

这篇关于店面形象到Windows Phone 7的隔离存放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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