Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to impliment webcam in my project.so get the following code but i am understanding that what is "using WinFormCharpWebCam;" and what is "imgpreview.image".
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using WinFormCharpWebCam;
namespace Camera_Sample
{
    public partial class Form1 : Form
    {
        WebCam webcam; //customized class created for handling the task of capturing image from Webcamera
        public Form1()
        {
            
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webcam = new WebCam();
            webcam.InitializeWebCam(ref imgCam);
        }

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

        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            webcam.Stop();
        }

        private void imgPreview_Click(object sender, EventArgs e)
        {

        }

        private void btnContinue_Click(object sender, EventArgs e)
        {
            webcam.Continue();
        }

        private void btnClick_Click(object sender, EventArgs e)
        {
            imgPreview.Image = imgCam.Image;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog sdialog = new SaveFileDialog();
            sdialog.FileName = "Image";// Default file name
            sdialog.DefaultExt = ".Jpg";// Default file extension
            sdialog.Filter = "Image (.jpg)|*.jpg"; // Filter files by extension

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






using System;
using System.IO;
using System.Text;
using WebCam_Capture;
using System.Collections.Generic;



namespace CSharpWebCam
{
    //Design by Dharma Iyer
    class WebCam
    {
        private WebCamCapture webcam;
        private System.Windows.Forms.PictureBox _FrameImage;
        private int FrameNumber = 30;
        public void InitializeWebCam(ref System.Windows.Forms.PictureBox ImageControl)
        {
            webcam = new WebCamCapture();
            webcam.FrameNumber = ((ulong)(0ul));
            webcam.TimeToCapture_milliseconds = FrameNumber;
            webcam.ImageCaptured += new WebCamCapture.WebCamEventHandler(webcam_ImageCaptured);
            _FrameImage = ImageControl;
        }

        void webcam_ImageCaptured(object source, WebcamEventArgs e)
        {
            _FrameImage.Image = e.WebCamImage;
        }

        public void Start()
        {
            webcam.TimeToCapture_milliseconds = FrameNumber;
            webcam.Start(0);
        }

        public void Stop()
        {
            webcam.Stop();
        }

        public void Continue()
        {
            // change the capture time frame
            webcam.TimeToCapture_milliseconds = FrameNumber;

            // resume the video capture from the stop
            webcam.Start(this.webcam.FrameNumber);
        }

        public void ResolutionSetting()
        {
            webcam.Config();
        }

        public void AdvanceSetting()
        {
            webcam.Config2();
        }


        internal void InitializeWebCam(System.Windows.Forms.PictureBox imgCam)
        {
            throw new NotImplementedException();
        }
    }
}
Posted
Updated 29-Jan-13 2:10am
v2
Comments
[no name] 31-Jan-13 8:23am    
is WinFormCharpWebCam.dll is system dll or it download from other site.

What is using WinFormCharpWebCam?

About the keyword "using":
The using directive has two uses:
- To permit the use of types in a namespace so you do not have to qualify the use of a type in that namespace:
C#
using System.Text;

- To create an alias for a namespace or a type.
C#
using Project = PC.MyCompany.Project;

or
C#
using WinFormCharpWebCam;


This means that you can now use the functionality that the namespace you are using provides.


Cheers,
Edo
 
Share this answer
 
using WinFormCharpWebCam; is a directive which allows you to use types etc from that namespace without giving the fully qualified name - see this reference[^]

For example
C#
WinFormCSharpWebCam.InitializeWebCam
becomes just
C#
InitializeWebCam


imgPreview.Image is referring to the Image property of a PictureBox control called imgPreview on the form

If you're struggling with these concepts then you might be better off getting hold of the entire project as is - see http://easywebcam.codeplex.com/[^]
 
Share this answer
 
All this code is really confusing! For webcam access I used Emgu CV, its a .NET library which is a wrapper around a C++ library Open CV. You should have a look at Emgu CV, here is a link to a tutorial[^] where you can access webcam with 7 lines of code.

I hope that helps buddy!
 
Share this answer
 
Comments
sureshsharma123 25-Nov-13 13:20pm    
WinFormCharpWebCam

in this line give an error that is The type or namespace name 'WinFormCharpWebCam' could not be found (are you missing a using directive or an assembly reference?)

please send me answer
Lyle12313 18-Aug-14 9:42am    
This code doesn't work on tablets with more than one webcam

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