Saturday, 4 July 2015

VB.NET :: Cara membuat webcam di vb.net


Create a New Project

Create a new WinForms project
  1. File -> New Project
  2. Templates -> Visual Basic -> Windows Forms Application
winform webcam project

Add the Dynamic .NET TWAIN Framework

Add reference to the project
  1. Right click on the project root -> Add Reference
  2. Click Browse to add the relevant library
twain library
Add the Dynamic .NET TWAIN component to the Toolbox
  1. Right click on the Toolbox panel -> Choose Items
  2. .NET Framework component -> Click Browse to add the relevant library (DynamicDotNetTWAIN.dll)
  3. Check DynamicDotNetTwain
twain component

Create the User Interface


webcam UI

Select Webcams


1
2
3
4
5
6
7
8
9
10
11
12
13
Try
 
     dynamicDotNetTwain1.SelectSource() ‘ select source
     Dim en As EnumSupportedDeviceType
     en = dynamicDotNetTwain1.SupportedDeviceType
 
     dynamicDotNetTwain1.IfShowUI = True
     dynamicDotNetTwain1.SetVideoContainer(Me.pictureBox1) ‘ display preview in PictureBox
 
     dynamicDotNetTwain1.OpenSource() ‘ make source work
 Catch exp As Exception
     MessageBox.Show(exp.Message)
 End Try
twain webcam source

webcam preview display

Acquire Image


1
2
3
4
5
6
Try
    dynamicDotNetTwain1.IfThrowException = True
    dynamicDotNetTwain1.EnableSource() ‘ acquire image
Catch exp As Exception
    MessageBox.Show(exp.Message)
End Try
acquire image

Remove the Image


1
dynamicDotNetTwain1.RemoveAllImages() ‘ remove image

Save the Image


1
2
3
4
5
6
If dlgFileSave.ShowDialog() = Windows.Forms.DialogResult.Cancel Then ‘ call system dialog
    Exit Sub
End If
strFileName = dlgFileSave.FileName ‘ get file name from dialog
dynamicDotNetTwain1.SaveAsBMP(strFileName, dynamicDotNetTwain1.CurrentImageIndexInBuffer)
‘ save image to disk


No comments:

Post a Comment