Get Image from webcam

10 pts.
Tags:
VB 6
VB 6.0
VB 6.0 Image Capture
Webcam
Dear sir, I wnat to capture a photo by clicking a button in VB 6.0 through webcam and store it to a desired location. Please help me
ASKED: November 28, 2008  9:26 AM
UPDATED: November 14, 2011  9:45 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

This is not a hard thing to do.

We are going to use some functions from USER32 and avicap32.dll, so the first thing is to declare them.

<pre>Private Declare Function SendMessage Lib “USER32″ Alias “SendMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private 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</pre>

To start using the cam, you need to create a capture window. This could be done in the Form_load event:

<pre>mCapHwnd = capCreateCaptureWindow(“WebcamCapture”, 0, 0, 0, 640, 480, Me.hwnd, 0)
SendMessage mCapHwnd, CONNECT, 0, 0</pre>

Then you get the frame, put it in a PictureBox control, and save it. This can be done in the Click event of a button:

<pre>SendMessage mCapHwnd, GET_FRAME, 0, 0
SendMessage mCapHwnd, COPY, 0, 0
Picture1.Picture = Clipboard.GetData
SavePicture Picture1.Image, “C:\picture.bmp”</pre>

At the end, you should disconnect the capture window:

<pre>SendMessage mCapHwnd, DISCONNECT, 0, 0</pre>

And that’s it.

If you want to see the camera preview, you could create a loop, in which you are getting frames until the user press the button to capture the picture.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following