vb.netwebcamdirectshowvideo-capturedirectshow.net

Capture still image from webcam (DirectSHowLib, VB.NET)


I'm ashamed, but I'll ask anyway: which is the most straightforward way to take a picture from a webcam with its default size and color-depth?

I started playing with DirectShowLib but I'm clueless... Can anyone guive me a guidance?

Imports DirectShowLib

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        PictureBox1.Image = Nothing

        Dim Cam As DsDevice = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice).FirstOrDefault

        If Cam IsNot Nothing Then

            Stop
            ' ... what now?

        End If

    End Sub

End Class

Solution

  • DirectShowLib's samples DxSnap, DxWebCam (C#) show how to capture from a webcam. There is also VB.NET DxLogoVB there, it does a different thing but is still good if you also look for some DriectShow.NET + VB.NET sample code.

    DxWebCam:

    A poor man's web cam program. This application runs as a Win32 Service.
    It takes the output of a capture graph, turns it into a stream of JPEG files, and sends it thru TCP/IP to a client application.

    DxSnap:

    Use DirectShow to take snapshots from the Still pin of a capture device. Note the MS encourages you to use WIA for this, but if you want to do in with DirectShow and C#, here's how.

    Note that this sample will only work with devices that output uncompressed video as RBG24. This will include most webcams, but probably zero tv tuners.