Introduction
C# Program to Print “Hello, World!”. This program is compiled and tested on a Visual Studio 2012.
C# Program to Print “Hello, World!”. This program is compiled and tested on a Visual Studio 2012.
Webcams, as an easy & cost-effective way to take images from video stream, is widely used in the business world. To save your time & energy to integrate webcam capture to your WinForms application, Dynamsoft developed the Dynamic .NET TWAIN SDK. With it, you can develop a web camera capture module in C# with a few lines of code. If you use VB.NET, please check out this blog post.
Create a simple Windows Forms Application in C#. Add Dynamic .NET TWAIN to the Toolbox: Assume you have it installed, you can browse and add DynamicDotNetTWAIN.dll in the installation folder of Dynamic .NET TWAIN (C:\Program Files (x86)\Dynamsoft\Dynamic .NET TWAIN Trial\Redistributable).
Drag & drop DynamicDotNetTwain to your form to create a control: Add a picturebox to the form as the video container. Add buttons for selecting cameras, acquiring images, and removing images. See below:
//Select a source
private void btnSelect_Click(object sender, EventArgs e)
{
try
{
dynamicDotNetTwain1.SelectSource();
dynamicDotNetTwain1.SetVideoContainer(pictureBox1);
dynamicDotNetTwain1.OpenSource();
//List the source name and resolutions
txtSourceName.Text = dynamicDotNetTwain1.CurrentSourceName;
int count = dynamicDotNetTwain1.ResolutionForCamList.Count;
for (int j = 0; j < count; j++)
{
string tempHeight = dynamicDotNetTwain1.ResolutionForCamList[j].Height.ToString();
string tempWidth = dynamicDotNetTwain1.ResolutionForCamList[j].Width.ToString();
string tempResolution = tempWidth + "X" + tempHeight;
comboResolution.Items.Insert(j, tempResolution);
comboResolution.SelectedIndex = 0;
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
//Acquire an image
private void btnAcquire_Click(object sender, EventArgs e)
{
try
{
dynamicDotNetTwain1.EnableSource();
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
}
Dynamic .NET TWAIN provides internal encoder for BMP, JPEG, PNG, (multi-page) TIF and (multi-page) PDF.
private void btnSave_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = "test.pdf";
saveFileDialog.Filter = "pdf files (*.pdf)|*.pdf|All files (*.*)|*.*";
if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
dynamicDotNetTwain1.SaveAllAsPDF(saveFileDialog.FileName);
}
}
To build your own webcam capture module using the SDK, download the 30-day free trial of Dynamic .NET TWAIN.
This artice was originally posted on CodeProject.
If you are interested in embedding webcam capture in a browser-based application, you may take a look at Dynamsoft Webcam SDK.
Copyright © . Designed By Templatezy