C# – Get image from webcam

cwebcam

I'm trying to find the way for getting image (only image, not video stream) from webcam in managed C#.
Usually people suggesting libraries, but they are old or commercial or under gpl.

How get image from webcam without third-party libraries?

upd.: thanks for Media Foundation, I shall use that.

Best Answer

Web cameras are supposed to deliver video feeds, not stills. So the native API you might be interested in is the one for video capture, which are DirectShow and Media Foundation.

The one you would most likely want is DirectShow, but it is not well suited to be interfaced from managed code, so you will need a DirectShow.NET which is open source wrapper. You typically start video streaming there and once you have a good image you stop the activity.

Or instead you might keep looking for a ready to use library which does the mentioned above for you.

One of DirectShow.NET samples does what you look for.

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.

It mentions WIA, however WIA API is not available for all (or any in recent OSes?) web cameras, WIA more targets device like scanners.

Other APIs are perhaps less suitable.

  • VFW ("avicap32.dll") limits you to a subset of devices, is simple yet not well interfaced into managed code
  • Media Foundation is not well available in earlier OS versions