Saving multiple images with one click

Jun 7, 2011 at 2:39 PM
Edited Jun 7, 2011 at 2:40 PM
So, I'm trying to create a Photoshop type application in Silverlight. The problem I'm currently trying to solve is trying to save multiple images which are on a canvas, 
like layers in Photoshop. I can save the canvas with all the images on it so it basically "flattens" the images and I can save one image per button click.
I would like to be able to save multiple images per button click. The problem I am running into is dealing with the SaveFileDialog class and the Stream class.
After an image is saved to a specific Stream, the stream is then closed. I've tried to use a Filestream and use a FileMethod.Open, but I haven't figured it out yet. 
Has anybody attempted this or can give me some pointers.

private void Save_Click(object sender, RoutedEventArgs e)
            if (Convert.ToInt32(wbmp.Pixels.GetValue(0)) == 0)
                wbmp = new WriteableBitmap(0, 0).FromResource("Images/Penguins.jpg");
                MyImage.Source = MyImage.Source;

            Canvas.SetLeft(I_wbmp, 200);
            Canvas.SetTop(I_wbmp, 200);
            //I_wbmp2.Visibility = System.Windows.Visibility.Collapsed;
            //MyImage.Visibility = System.Windows.Visibility.Collapsed;

            ExtendedImage ExtImg = canvas1.ToImage();
            //ExtendedImage ExtImg = I_wbmp.ToImage();
            //ExtendedImage ExtImg2 = I_wbmp2.ToImage();
            //ExtendedImage ExtImg3 = MyImage.ToImage();

            SaveFileDialog SaveDialog = new SaveFileDialog();

            SaveDialog.Filter = "Image Files (*.png, *.jpg)|*.png;*.jpg";

            if (SaveDialog.ShowDialog() == true)
                Stream stream = SaveDialog.OpenFile();
                using (stream)
                    // Use the write to stream extension method to write the image to the specified stream.
                    // The image encoder is selected by the extension of the name of the image.
                    string str = SaveDialog.SafeFileName;
                    Stream stream2 = stream;
                    ExtImg.WriteToStream(stream, str);

Jun 7, 2011 at 3:25 PM
Do you want to save multiple images to one stream?
Jun 7, 2011 at 3:31 PM

I would like to save the images to the same directory by only asking for the path once. From there I would dynamically create the names of the images. I want to avoid asking the user to save each image they have on the canvas, plus I can't initiate the ShowDialog() without a user interaction. I can only think of dynamically creating a save button for each image. I would like to avoid that. 

Jun 7, 2011 at 3:39 PM
This is not possible in Silverlight because of security reasons.
Jun 7, 2011 at 3:40 PM

I see, thank you for your speedy response!