How to use saveFileDialog for saving images in C#?

c#, image, savefiledialog

Solution

You can use the SaveFileDialog like this:

SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Images|*.png;*.bmp;*.jpg";
ImageFormat format = ImageFormat.Png;
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    string ext = System.IO.Path.GetExtension(sfd.FileName);
    switch (ext)
    {
        case ".jpg":
            format = ImageFormat.Jpeg;
            break;
        case ".bmp":
            format = ImageFormat.Bmp;
            break;
    }
    pictureBox1.Image.Save(sfd.FileName, format);
}

Problem

Possible Duplicate: Issue while saving image using savefiledialog I use windows forms in C#. How should I use saveFileDialog? I have picturebox and on the picture box there is an image and I want to save it. Loaded image is bmp. I want to save it as one of 4 formats: bmp, jpeg, png, tiff. I read some some notes on MDSN and also tryed it but I probably do something wrong. So I better ask how should be it write? How should be wrote method private void saveFileDialog1_FileOk(object sender, CancelEventArgs e) and how should look like property saveFileDialog.Filter? Thanks EDIT: What I've tryed: Issue while saving image using savefiledialog EDIT2: I tryed this filter ``` Filter = bmp (*.bmp)|*.bmp|jpeg (*.jpeg)|*.jpeg|png (*.png)|*.png|tiff (*.tiff)|*.tiff ```

Original source