1

有没有一种简单的方法可以将变量 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);
                }
            }
        }



    }
4

1 回答 1

0

有两种方法可以做到这一点。简单的方法(实现这个名为 EZ_iso 的免费 dll)或困难的方法。找出孤立的存储过程和所有边缘情况异常。

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

如果您实现 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);
于 2014-06-04T18:34:35.490 回答