Get image from webcam

I am trying to find a way to get an image (only an image, not a video stream) from a webcam in managed C #. Usually people offer libraries, but they are old or commercial or under gpl.

How to get a webcam image without third-party libraries?

upd .: thanks Media Foundation, I will use it.

+1
source share
3 answers

It is assumed that webcams will deliver video streams, rather than still ones. So the native API that you are interested in is the one that is designed to capture videos that are DirectShow and Media Foundation.

The one you most likely want is DirectShow, but it is not suitable for interacting with managed code, so you will need DirectShow.NET , which is an open source shell. Usually you start streaming video, and as soon as you have a good image, you stop activity.

Or instead, you can continue to search for a ready-to-use library that does this for you higher.

One of the DirectShow.NET samples does what you are looking for.

DxSnap - Use DirectShow to create snapshots from the Still Capture pin. Note that MS recommends that you use WIA for this, but if you want to do it using DirectShow and C #, how to do it.

It mentions the WIA, but the WIA API is not available for all (or any other modern OS) webcams; the WIA targets the device more, such as scanners.

Other APIs may be less suitable.

  • VFW ("avicap32.dll") limits you to a subset of devices, simple but not very well connected with managed code.
  • Media Foundation is not available in earlier versions of the OS
+2
source

I wrote this many years ago

http://www.vbforums.com/showthread.php?344471-Vb.Net-WebCam-Class-(ICam )) on VB.net

Can you easily port it to C #?

+1
source
+1
source

All Articles