Home > Uncategorized > Capture webcam to file (VB.NET)

Capture webcam to file (VB.NET)

I decided to take a look again at my webcam streamer software that I wrote a few years ago for www.mobilewebcam.co.uk  – to see if I could improve upon it. One of my biggest gripes with the software, was that it used the clipboard to hold the temporary image from the webcam prior to upload. This meant while the webcam software was running, the clipboard was useless.

I used the avicap32 API, which is much lower-level than the DirectX equivalent, and much more awkward to use, since you are dealing with a DLL that was never designed to work with .NET.

I’m omitting the setup code, you can probably get this from another site if you search, I just wanted to include the few lines of code required to take the image from the camera to a file:

Dim sFileName As String
sFileName = System.IO.Path.GetTempFileName
Call SendMessageAsString(lwndC, WM_CAP_FILE_SAVEDIB, 0&, sFileName)
Dim bmp As New System.Drawing.Bitmap(sFileName)

Now, SendMessageAsString is an alias of the ubiquitous SendMessage API call, with a twist as follows;

    Declare Function SendMessageAsString Lib “user32” Alias “SendMessageA” (ByVal hWnd As Integer, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr

WM_CAP_FILE_SAVEDIB is defined as  WM_USER + 25 (&H400S), and lwndC is a window handle to the capture window, which is set up with capCreateCaptureWindowA.

 

 

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: