将WriteableBitmap保存到IsolatedStorageFileStream

时间:2013-11-25 08:12:12

标签: windows-phone bitmapimage isolatedstoragefile writablebitmap

有没有一种简单的方法可以将变量WriteableBitmap的内容保存到IsolatedStorageFile?我正在编写一个程序来处理WriteableBitmap中的像素,然后将处理后的位图保存为文件* .bmp并将其存储在“已保存的图片”目录中。我有将WriteableBitmap保存为jpeg文件的代码,但正如我之前所说,我不想以任何方式压缩图形。请帮我解决我的问题。

private void Save_as_bmp(object sender, RoutedEventArgs e)
    {



        String temp = "photo.bmp";

        using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (myIsolatedStorage.FileExists(temp))
            {
                myIsolatedStorage.DeleteFile(temp);
            }

            IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(tempJPEG);

            //Writeable wb declared in another method

            //JPEG compression  
            //wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100); 

            //  In this place I need to  save variable wb to file stream without any compression
            // something like - fileStram = wb.content;


            fileStream.Close();
        }


        using (IsolatedStorageFile myIsolatedStorage2 = IsolatedStorageFile.GetUserStoreForApplication())
        {
            using (IsolatedStorageFileStream fileStream2 = myIsolatedStorage2.OpenFile("photo.bmp", FileMode.Open, FileAccess.Read))
            {

                try
                {

                    var mediaLibrary2 = new MediaLibrary();
                    mediaLibrary2.SavePicture("raster_graphic", fileStream2);
                    //mediaLibrary2.SavePictureToCameraRoll("raster_graphic", fileStream2);
                    MessageBox.Show("Image saved");
                    //fileStream2.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error, exception: " + ex.Message);
                }
            }
        }



    }

1 个答案:

答案 0 :(得分:0)

有两种方法可以做到这一点。简单方法(implement this free dll called EZ_iso)或艰难的方式。找出孤立的存储过程和所有边缘情况例外。

该链接还有文档和源代码,因此如果您有兴趣自己学习如何操作,可以从那里开始。

如果你实现了DLL,它就会是这样的。

void CameraTaskCapture_Completed(object sender, PhotoResult e){ 
    //Doesn't have to be from camera capture. This is just the example from the documentation 
    //Just pass in a BitmapImage
    EZ_Iso.IsolatedStorageAccess.SaveImage(“MyImage”, e.ChosenPhoto); 
} 

然后就是你检索它的方式

//This could also be a BitmapImage instead of an ImageControl.Source
ImageControl.Source = EZ_Iso.IsolatedStroageAccess.GetImage(“MyImage”,800,480);
相关问题