我如何采取一个位图图像,并保存为的Windows Phone 7设备上的JPEG图像文件? [英] How do I take a bitmap image and save as a JPEG image file on a Windows Phone 7 device?

查看:185
本文介绍了我如何采取一个位图图像,并保存为的Windows Phone 7设备上的JPEG图像文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望创建一个函数,它接受一个的BitmapImage ,并将其保存为JPEG本地的Windows Phone 7设备的独立存储于:

 的静态公共无效saveImageLocally(串吧code,BitmapImage的anImage)
{
 //保存anImage为JPEG设备上的位置
}
 

我如何做到这一点?我假设我用 IsolatedStorageFile 不知何故?

感谢。

编辑:

下面是我到目前为止发现...谁能确认这是否是这样做的正确方法?

 的静态公共无效saveImageLocally(串吧code,BitmapImage的anImage)
    {
        WriteableBitmap的WB =新的WriteableBitmap的(anImage);

        使用(VAR ISF = IsolatedStorageFile.GetUserStoreForApplication())
        {
            使用(VAR FS = isf.CreateFile(巴code +.JPG))
            {
                wb.SaveJpeg(FS,wb.PixelWidth,wb.PixelHeight,0,100);
            }
        }
    }

    静态公共无效deleteImageLocally(串吧code)
    {
        使用(IsolatedStorageFile的MyStore = IsolatedStorageFile.GetUserStoreForApplication())
        {
            MyStore.DeleteFile(酒吧code +.JPG);
        }
    }

    静态公网的BitmapImage getImageWithBar code(串吧code)
    {
        BitmapImage的BI =新的BitmapImage();

        使用(VAR ISF = IsolatedStorageFile.GetUserStoreForApplication())
        {
            使用(VAR FS = isf.OpenFile(巴code +.JPG,FileMode.Open))
            {
                bi.SetSource(FS);
            }
        }

        返回双向;
    }
 

解决方案

要保存它:

  VAR BMP =新的WriteableBitmap的(的BitmapImage);
使用(IsolatedStorageFile存储= IsolatedStorageFile.GetUserStoreForApplication())
    {
        使用(IsolatedStorageFileStream流= storage.CreateFile(@MyFolder的\ file.jpg))
        {
            bmp.SaveJpeg(流,200,100,0,95);
            stream.Close();
        }
    }
 

是的,你在你的编辑添加的内容正是我以前做过:)它的工作原理。

I am looking to create a function that takes a BitmapImage and saves it as a JPEG on the local Windows Phone 7 device in isolated storage:

static public void saveImageLocally(string barcode, BitmapImage anImage)
{
 // save anImage as a JPEG on the device here
}

How do I accomplish this? I'm assuming I used IsolatedStorageFile somehow?

Thanks.

EDIT:

Here is what I have found so far... can anyone confirm if this is the correct way to do this?

    static public void saveImageLocally(string barcode, BitmapImage anImage)
    {
        WriteableBitmap wb = new WriteableBitmap(anImage);

        using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (var fs = isf.CreateFile(barcode + ".jpg"))
            {
                wb.SaveJpeg(fs, wb.PixelWidth, wb.PixelHeight, 0, 100);
            }
        }
    }

    static public void deleteImageLocally(string barcode)
    {
        using (IsolatedStorageFile MyStore = IsolatedStorageFile.GetUserStoreForApplication())
        {
            MyStore.DeleteFile(barcode + ".jpg");
        }
    }

    static public BitmapImage getImageWithBarcode(string barcode)
    {
        BitmapImage bi = new BitmapImage();

        using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (var fs = isf.OpenFile(barcode + ".jpg", FileMode.Open))
            {
                bi.SetSource(fs);
            }
        }

        return bi;
    }

解决方案

To save it:

var bmp = new WriteableBitmap(bitmapImage);
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream stream = storage.CreateFile(@"MyFolder\file.jpg"))
        {
            bmp.SaveJpeg(stream, 200, 100, 0, 95);
            stream.Close();
        }
    }

Yes, the stuff you added in your edit is exactly what I have done before :) it works.

这篇关于我如何采取一个位图图像,并保存为的Windows Phone 7设备上的JPEG图像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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