• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1483
  • Last Modified:

Capture Video from WebCam in VB.NET

I would like to capture video from a webcam in VB.Net.  The following sourcecode displays the video correctly:

Private Sub cmdCapture_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCapture.Click
Dim temp As Integer      
hwdc = capCreateCaptureWindow("Dixanta Vision System", ws_child Or ws_visible, 0, 0, 320, 240, Picture1.Handle.ToInt32, 0)
If (hwdc <> 0) Then
   temp = SendMessage(hwdc, wm_cap_driver_connect, 0, 0)
   temp = SendMessage(hwdc, wm_cap_set_preview, 1, 0)
   temp = SendMessage(hwdc, WM_CAP_SET_PREVIEWRATE, 30, 0)
   startcap = True
Else
   MsgBox("No Webcam found")
End If
End Sub

I have added the code temp = SendMessage(hwdc, WM_CAP_SEQUENCE, 0, 0L)
This does create a video file - however there is no video, only sound.

Can you help me to get this snippet to work - or do you have other full source code that you can share?
0
ErichN
Asked:
ErichN
1 Solution
 
AlexFMCommented:
There is the way to do this using pure .NET code, without PInvoke - search for VB .NET DirectShow samples. This sample is written in C#, but this is class which can be placed to Class Library and used from any .NET language:

http://www.codeproject.com/cs/media/directxcapture.asp

Notice that capCreateCaptureWindow is part of Video Capture SDK. This SDK is not recommended for use by Microsoft both in managed and unmanaged applications, and replaced by DirectShow SDK.
0
 
ErichNAuthor Commented:
Thank you Alex.  Your answer has helped me implementing my project.  As a small thankyou I have increased the points for you.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now