Nah kali ini saya akan share caranya, caranya cukup mudah, di mbah google juga sudah banyak, tp kadang msh banyak yang kurang sesuai, seperti pas preview/start camera tidak muncul gambar kita, jd kita tidak bisa lihat gambar atau posisi kita seperti apa nanti pas di capture..
nah begini caranya :
- Design Form Seperti dibawah ini (Saya anggap anda sudah memahami cara design form)
Tool yang diperlukan adalah:
1. 2 buah picture box
2. 7 buah button
PictureBox1 = imgVideo
PictureBox2 = imgCapture
Button1 = bntStart
Button2 = bntStop
Button3 = bntContinue
Button4 = bntCapture
Button5 = bntSave
Button6 = bntVideoFormat
Button7 = bntVideoSource
- Setelah selesai Design Form, Lanjut ke Coding, Lets Go !!!
- Setelah Add Reference, tambahkan 2 buah Class diproject anda, class1 kasih nama Helper.vb dan class2 kasih nama WebCam.vb
- Coding class Helper.vb
Imports System.IO
Imports System.Linq
Imports System.Text
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Windows.Forms
'Design by Pongsakorn Poosankam
Class Helper
Public Shared Sub SaveImageCapture(ByVal image As System.Drawing.Image)
Dim s As 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
' Process save file dialog box results
If s.ShowDialog() = DialogResult.OK Then
' Save Image
Dim filename As String = s.FileName
Dim fstream As New FileStream(filename, FileMode.Create)
image.Save(fstream, System.Drawing.Imaging.ImageFormat.Jpeg)
fstream.Close()
End If
End Sub
End Class
- Coding class WebCam.vb
Imports System.IO
Imports System.Linq
Imports System.Text
Imports WebCam_Capture
Imports System.Collections.Generic
'Design by Pongsakorn Poosankam
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((0))
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]()
' change the capture time frame
webcam.TimeToCapture_milliseconds = FrameNumber
' resume the video capture from the stop
webcam.Start(Me.webcam.FrameNumber)
End Sub
Public Sub ResolutionSetting()
webcam.Config()
End Sub
Public Sub AdvanceSetting()
webcam.Config2()
End Sub
End Class
- Double Click Form1 anda, nama form 1 saya kasih nama mainWinForm.
webcam = New WebCam()
webcam.InitializeWebCam(imgVideo)
End Sub
- Coding bntStart
webcam.Start()
End Sub
- Coding bntStop
webcam.Stop()
End Sub
- Coding bntContinue
webcam.Continue()
End Sub
- Coding bntCapture
imgCapture.Image = imgVideo.Image
End Sub
- Coding bntSave
Helper.SaveImageCapture(imgCapture.Image)
End Sub
- Coding bntVodeoFormat
webcam.ResolutionSetting()
End Sub
- bntVodeoSource
webcam.AdvanceSetting()
End Sub
- Lalu RUN project, Selesai . .
Oke Langsung saya anda bisa download projectnya dibawah ini :
Download DLL nya Disini Aja
Download Source Code Project Disini Aja
Semoga Bermanfaat :)
0 Comments
isi komentar anda di sini