Click here to Skip to main content
15,905,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am Using Web Cam In Window Aplication
I am Able to take picture And Save it in to My computer
Using
Helper.SaveImageCapture(pictureBox2.Image);

And this mathod ask me location where You want save file

But I want save image file automaticly Whithin aplication specfied folder
How it will be possible
Thanks in advance

My Code look Like This


C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WinFormCharpWebCam;
using System.IO;
namespace Photosaved
{
    public partial class Form1 : Form
    {
        WebCam webcam;
        public Form1()
        {
            InitializeComponent();
            webcam = new WebCam();
            webcam.InitializeWebCam(ref pictureBox1);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            webcam.Start();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            pictureBox2.Image = pictureBox1.Image;
        }

       

       

        private void save_Click(object sender, EventArgs e)
        {
           Helper.SaveImageCapture(pictureBox2.Image);
           
        }
    }
}

Helper Class

using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace WinFormCharpWebCam
{
    //Design by Pongsakorn Poosankam
    class Helper
    {
        
        public static void SaveImageCapture(System.Drawing.Image image)
        {

            SaveFileDialog s = new SaveFileDialog();
            s.InitialDirectory="E:\\Office Work\\Window Aplication\\imagelocation\\Photosaved\\Photosaved\\Image\\";

            s.FileName = "Image";// Default file name
            s.DefaultExt = ".Jpg";// Default file extension
            s.Filter = "Image (.jpg)|*.jpg"; // Filter files by extension
         //  E:\Office Work\Window Aplication\imagelocation\Photosaved\Photosaved\img\
            // Show save file dialog box
            // Process save file dialog box results
            if (s.ShowDialog()==DialogResult.OK)
            {
                // Save Image
                string filename = s.FileName;
                string location=s.InitialDirectory;
                FileStream fstream = new FileStream(filename, FileMode.Create);
               
                image.Save(fstream, System.Drawing.Imaging.ImageFormat.Jpeg);
                fstream.Close();

            }

        }
    }
Posted
Updated 19-Jun-13 8:08am
v2
Comments
[no name] 19-Jun-13 13:52pm    
And what is your question? You have code right here that shows you how to save an image to any directory you want and you can't see it?

1 solution

Try this

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WinFormCharpWebCam;
using System.IO;
namespace Photosaved
{
    public partial class Form1 : Form
    {
        WebCam webcam;
        public Form1()
        {
            InitializeComponent();
            webcam = new WebCam();
            webcam.InitializeWebCam(ref pictureBox1);
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            webcam.Start();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            String FilePath = "E:\\Office Work\\Window Aplication\\imagelocation\\Photosaved\\Photosaved\\Image\\";
            
            pictureBox2.Image = pictureBox1.Image;

            FileStream fstream = new FileStream(FilePath, FileMode.Create, FileAccess.Write);
               
            image.Save(fstream, System.Drawing.Imaging.ImageFormat.Jpeg);
            fstream.Close();
        }
    }
}
 
Share this answer
 
v2

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