c# – Easiest way to get bitmap from camera in c #

Question:

The only thing I found was the AFORGE.net library with the SNAPSHOT MAKER sample. But it also implements streaming video in control, and bitmap removal, in general, very rich functionality that I will not need at the root. I only need a bitmap (and the delay between shots is more than a minute), maybe there is a more graceful solution to get it from the camera?

Answer:

If you do not drag along bulky libraries like AForge.NET (which still uses the DirectShow API in the example from the parallel answer), you can limit yourself to a simpler DirectShow.NET library, which has at least two close examples:

\ DirectShowSamples-2010-February \ Samples \ Misc \ 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.

\ DirectShowSamples-2010-February \ Samples \ Capture \ 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.

In both cases, something similar happens: the initialization of capturing video from the camera and further work with frames (further with video – to taste: skipping unnecessary, processing the necessary).

You need to keep in mind the following: webcams often have an unpleasant feature to start working for a long time (initialization, focusing and adjusting the white balance, etc.). That is, for a snapshot, you need to shoot and discard unnecessary frames all the time, then, on a signal, grab the first available (or the last available) frame.

Scroll to Top