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.



Categories: Uncategorized
  1. ashleyjon0112
    September 16, 2021 at 7:42 am

    Logitechs Software is bugged out beyond use.. at least for me. When I recorded footage with it and want to close it afterwards, it freezes. Like totally. It freezes so deep, that the pc can’t end the process and needs to be crashed. :/ Actually, that problem was the reason for coming here.. 😀 OBS was a thought.. yes. Virtual Dub, as well. Are they CPU intensive? If I’d wanted to run them besides Dxtroy and a game, with an i5.. plausible.


  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 )

Connecting to %s

%d bloggers like this: