BUAT APLIKASI WEBCAM PAKE VISUAL BASIC 6.0

 

clip_image002

Lama tidak buat tutorial tentang Visual Basic, tapi kali ini saya berbagi tutorial bagaimana cara membuat aplikasi yang berfungsi untuk melakukan capture image dari webcam.

Tak usah basa basi sob langsung aja ke TKP…

Langkah 1.

Jalankan visual basic sobat dan buatlah form aplikasi seperti gambar berikut :

clip_image004

Dengan keterangan sebagai berikut :

Label1, Caption : MY WEBCAM

PictureBox, Name : gbrWebcam

CommonDialog, Name : CDialog

CommandButton1, Name : cmdMulai; Caption : Mulai

CommandButton2, Name : cmdSimpan; Caption : Simpan

CommandButton3, Name : cmdSetting; Caption : Setting

CommandButton4, Name : cmdTutup; Caption : Tutup

Langkah 2.

Jika langkah 1 selesai, tambahkan sebuah module dan tuliskan koding berikut pada module yang soba buat :

Public Const WS_CHILD As Long = &H40000000
Public Const WS_VISIBLE As Long = &H10000000
Public Const WM_USER As Long = &H400
Public Const WM_CAP_START As Long = WM_USER
Public Const WM_CAP_DRIVER_CONNECT As Long = WM_CAP_START + 10
Public Const WM_CAP_DRIVER_DISCONNECT As Long = WM_CAP_START + 11
Public Const WM_CAP_SET_PREVIEW As Long = WM_CAP_START + 50
Public Const WM_CAP_SET_PREVIEWRATE As Long = WM_CAP_START + 52
Public Const WM_CAP_DLG_VIDEOFORMAT As Long = WM_CAP_START + 41
Public Const WM_CAP_FILE_SAVEDIB As Long = WM_CAP_START + 25
Public Declare Function capCreateCaptureWindow _
Lib "avicap32.dll" Alias "capCreateCaptureWindowA" _
(ByVal lpszWindowName As String, ByVal dwStyle As Long _
, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long _
, ByVal nHeight As Long, ByVal hwndParent As Long _
, ByVal nID As Long) As Long
Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long _
, ByVal wParam As Long, ByRef lParam As Any) As Long

 

image

Untuk Module telah selesai sobat buat dan lanjutkan pada langkah 3.

 

Langkah 3.

Klik 2x form project sobat dan tuliskan koding berikut :

Dim hCap As Long

Pada General Declarations

clip_image008

 

Lanjutkan dengan klik 2x tombol “Mulai” dan tuliskan koding berikut :

Private Sub cmdMulai_Click()
hCap = capCreateCaptureWindow("Take a Camera Shot" _
, WS_CHILD Or WS_VISIBLE, 0, 0, gbrWebcam.Width _
, gbrWebcam.Height, gbrWebcam.hWnd, 0)
If hCap <> 0 Then
Call SendMessage(hCap, WM_CAP_DRIVER_CONNECT, 0, 0)
Call SendMessage(hCap, WM_CAP_SET_PREVIEWRATE, 66, 0&)
Call SendMessage(hCap, WM_CAP_SET_PREVIEW, CLng(True), 0&)
End If
End Sub

 

clip_image010

Lanjut lagi…

Klik 2x tombol “Simpan” dan tuliskan koding berikut :

Private Sub cmdSimpan_Click()
Dim sFileName As String
Call SendMessage(hCap, WM_CAP_SET_PREVIEW, CLng(False), 0&)
With CDialog
.CancelError = True
.Flags = cdlOFNPathMustExist Or cdlOFNOverwritePrompt
.Filter = "JPEG Picture(*.jpg)|*.jpg|All Files|*.*"
.ShowSave
sFileName = .FileName
End With
Call SendMessage(hCap, WM_CAP_FILE_SAVEDIB, 0&, ByVal CStr(sFileName))
DoFinally:
Call SendMessage(hCap, WM_CAP_SET_PREVIEW, CLng(True), 0&)
End Sub

 

clip_image012

Klik 2x tombol “Seting” dan tuliskan koding berikut :

Private Sub cmdSeting_Click()
Dim temp As Long
temp = SendMessage(hCap, WM_CAP_DLG_VIDEOFORMAT, 0&, 0&)
End Sub

 

clip_image014

 

Terakhir…

Klik 2x tombol “Tutup” dan silahkan sobat tulis koding berikut :

Private Sub cmdTutup_Click()
Dim temp As Long
temp = SendMessage(hCap, WM_CAP_DRIVER_DISCONNECT, 0&, 0&)
Unload Me
End Sub

 

clip_image016

Sekarang aplikasi siap dijalankan…

 

Share this article :
 

+ comments + 6 comments

February 22, 2015 at 10:49 PM

terima kasih sudah share

September 15, 2015 at 4:08 PM

gan klo untuk webcam cctv gimana code nya

Anonymous
November 30, 2015 at 2:32 PM

Mantap.. mau tanya lagi... kalo menampilkan langsung hasil capture ke form sebelum disimpan bisa gak ? Trus gimana caranya... ya seperti preview gambar sebelum disimpan.
Trimaksh

December 12, 2015 at 2:05 AM

gan, kalau kasusnya mendeteksi objek (bola), terus di rekam setelah itu bola hilang terus ada event alarm gmna gan, mhn pencerahannya

May 27, 2016 at 9:52 PM

zhe keen. itu kemungkinan gabisa lewat vb. sekalinya bisa akan sangat rumit. umumnya untuk melakukan kaya gtu menggunakan bahasa c/ bahasa tingkat menengah-rendah karena kemampuannya mengakses penuh dukungan hardware

June 7, 2016 at 5:57 PM

gimana caranya menampilkan capture ke forum forum

Post a Comment

Terima Kasih Sudah Meninggalkan Komentar...

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. ingin berbagi - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger