【问题标题】:Save WritableBitmap to IsolatedStorageFileStream将 WritableBitmap 保存到 IsolatedStorageFileStream
【发布时间】:2013-11-25 08:12:11
【问题描述】:

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



    }

【问题讨论】:

  • 我不期望完成的代码。请给我一个提示。我忘了补充说我正在 windows phone 8 上编写程序。

标签: windows-phone bitmapimage isolatedstoragefile writablebitmap


【解决方案1】:

有两种方法可以做到这一点。简单的方法(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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多