Hi priyajsr,
Check the below sample.
First Download the dll from the below link and add its reference in your project.
http://www.mediafire.com/?dxrnc433pfrp7mu
Form Design
I have added two PictureBox controls in the Form and 7 Button controls.
Class File
C#
using WebCam_Capture;
namespace _WebCam_PictureBox
{
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();
}
}
}
VB.Net
Imports WebCam_Capture
Class WebCam
Private webcam As WebCamCapture
Private _FrameImage As System.Windows.Forms.PictureBox
Private FrameNumber As Integer = 30
Public Sub InitializeWebCam(ByRef ImageControl As System.Windows.Forms.PictureBox)
webcam = New WebCamCapture()
webcam.FrameNumber = (CULng((0UL)))
webcam.TimeToCapture_milliseconds = FrameNumber
AddHandler webcam.ImageCaptured, AddressOf webcam_ImageCaptured
_FrameImage = ImageControl
End Sub
Private Sub webcam_ImageCaptured(ByVal source As Object, ByVal e As WebcamEventArgs)
_FrameImage.Image = e.WebCamImage
End Sub
Public Sub Start()
webcam.TimeToCapture_milliseconds = FrameNumber
webcam.Start(0)
End Sub
Public Sub [Stop]()
webcam.[Stop]()
End Sub
Public Sub [Continue]()
webcam.TimeToCapture_milliseconds = FrameNumber
webcam.Start(Me.webcam.FrameNumber)
End Sub
Public Sub ResolutionSetting()
webcam.Config()
End Sub
Public Sub AdvanceSetting()
webcam.Config2()
End Sub
End Class
Code
C#
using System;
using System.IO;
using System.Windows.Forms;
namespace _WebCam_PictureBox
{
public partial class mainWinForm : Form
{
public mainWinForm()
{
InitializeComponent();
}
WebCam webcam;
private void mainWinForm_Load(object sender, EventArgs e)
{
webcam = new WebCam();
webcam.InitializeWebCam(ref imgVideo);
}
private void bntStart_Click(object sender, EventArgs e)
{
webcam.Start();
}
private void bntStop_Click(object sender, EventArgs e)
{
webcam.Stop();
}
private void bntContinue_Click(object sender, EventArgs e)
{
webcam.Continue();
}
private void bntCapture_Click(object sender, EventArgs e)
{
imgCapture.Image = imgVideo.Image;
}
private void bntSave_Click(object sender, EventArgs e)
{
SaveImageCapture(imgCapture.Image);
}
private void bntVideoFormat_Click(object sender, EventArgs e)
{
webcam.ResolutionSetting();
}
private void bntVideoSource_Click(object sender, EventArgs e)
{
webcam.AdvanceSetting();
}
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.
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();
}
}
}
}
VB.Net
Imports System.IO
Public Class Form1
Dim webcam As WebCam
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
webcam = New WebCam()
webcam.InitializeWebCam(imgVideo)
End Sub
Private Sub bntStart_Click(ByVal sender As Object, ByVal e As EventArgs)
webcam.Start()
End Sub
Private Sub bntStop_Click(ByVal sender As Object, ByVal e As EventArgs)
webcam.[Stop]()
End Sub
Private Sub bntContinue_Click(ByVal sender As Object, ByVal e As EventArgs)
webcam.[Continue]()
End Sub
Private Sub bntCapture_Click(ByVal sender As Object, ByVal e As EventArgs)
imgCapture.Image = imgVideo.Image
End Sub
Private Sub bntSave_Click(ByVal sender As Object, ByVal e As EventArgs)
SaveImageCapture(imgCapture.Image)
End Sub
Private Sub bntVideoFormat_Click(ByVal sender As Object, ByVal e As EventArgs)
webcam.ResolutionSetting()
End Sub
Private Sub bntVideoSource_Click(ByVal sender As Object, ByVal e As EventArgs)
webcam.AdvanceSetting()
End Sub
Public Shared Sub SaveImageCapture(ByVal image As System.Drawing.Image)
Dim s As SaveFileDialog = New SaveFileDialog()
s.FileName = "Image"
s.DefaultExt = ".Jpg"
s.Filter = "Image (.jpg)|*.jpg"
If s.ShowDialog() = DialogResult.OK Then
Dim filename As String = s.FileName
Dim fstream As FileStream = New FileStream(filename, FileMode.Create)
image.Save(fstream, System.Drawing.Imaging.ImageFormat.Jpeg)
fstream.Close()
End If
End Sub
End Class
Screenshots
While Capturing
Saved Image