Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if iwant to save the capture image directly in document file with out the saveFiledialog
for example the images saved in document file in different names like "image 1,image 2,..... and so on"


this is the code i take it from this site
https://sites.google.com/site/webcamlibrarydotnet/winfrom-and-csharp-sample-code-and-download[^]

C#
public static void SaveImageCapture(System.Drawing.Image image)
        {

            SaveFileDialog s = new SaveFileDialog();
            s.FileName = "Image";// Default file name
            s.DefaultExt = ".Jpg";// Default file extension
            s.Filter = "Image (.jpg)|*.jpg"; // Filter files by extension

            // Show save file dialog box
            // Process save file dialog box results
            if (s.ShowDialog() == DialogResult.OK)
            {
                // Save Image
                string filename = s.FileName;
                FileStream fstream = new FileStream(filename, FileMode.Create);
                image.Save(fstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                fstream.Close();

            }

        }


can anybody help

Thanks in Advance
Rawa
Posted

1 solution

Hi,

Just alter the method so that you pass a file name instead:

C#
public void SaveImageCapture(System.Drawing.Image image, string filename)
{
    FileStream fstream = new FileStream(filename, FileMode.Create);
    image.Save(fstream, System.Drawing.Imaging.ImageFormat.Jpeg);
    fstream.Close();
}


Using the function:

C#
SaveImageCapture(image, @"c:\test.jpg");


Kind regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900