Search code examples
c#videowebcamphotos

How to take a picture using the default webcam in C#?


I need help to make my program. I have developed a form in C# that only has a textbox and a button to take a photo using the webcam and save it in the file path specified.

So I need a method to start the webcam, take a photo and save it in the file path and close the webcam immediately. No need to see what the webcam shows, just take the photo very fast and save it.

enter image description here

Any idea how I can do that? All comments are welcome. Thanks in advance.


Solution

  • Windows APIs to access a webcam are native, but you can use well known wrappers:

    First, DirectShow.NET's DxSnap sample

    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.

    Related on StackOverflow:

    Second, Media Foundation.NET which wraps Media Foundation API

    Then, other libraries, that eventually wrap mentioned above APIs (including referenced by links above)