我希望创建一个使用BitmapImage并将其另存为JPEG的函数,并将其保存在本地Windows Phone 7设备的独立存储中:

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


我该怎么做?我假设我以某种方式使用了IsolatedStorageFile

谢谢。

编辑:

这是到目前为止我发现的...任何人都可以确认这是否是正确的方法吗?

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

最佳答案

要保存它:

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


是的,您在编辑中添加的内容正是我之前所做的:)。

关于c# - 如何在Windows Phone 7设备上拍摄位图图像并将其另存为JPEG图像文件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9423565/

10-13 08:28