Question

Is there a simple way to save the contents of the variable WriteableBitmap to IsolatedStorageFile? I am writing a program that processes the pixels in a WriteableBitmap, and then saves the processed bitmap as file *.bmp and stores it in the "saved pictures" directory. I have code that saves the WriteableBitmap as a jpeg file, but as I said before I do not want to compress graphics in any way. Please help me to solve my problem.

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



    }

No correct solution

OTHER TIPS

There are two ways to do this. The easy way (implement this free dll called EZ_iso) or the hard way. Figure out isolated storage procedures and all the edge case exceptions.

There is also documentation and source code at that link so if you are interested in learning how to do it yourself you can start there.

If you implement the DLL it's going to be something like this.

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

Then this is how you retrieve it

//This could also be a BitmapImage instead of an ImageControl.Source
ImageControl.Source = EZ_Iso.IsolatedStroageAccess.GetImage(“MyImage”,800,480);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top