After much searching, I was almost frustrated as there was no simple solution to what I wanted to accomplish.
Make a simple C#/.Net/Desktop application that will:
1. Connect to a webcam
2. Show the video being "seen" by the webcam
3. Take a snapshot of the video and save it as an image.
The WIA (Windows Image Acquisition) worked wonders with the flatbed scanner. So I wanted to extend its use for video.
Fortunately there is WIAVideo.dll that does exactly what I need to do.
Basically the steps are:
1. Detect the video input devices you have
2. get the device ID
3. Use WiaVideo to take a snapshot.
No screenshots this time.. but this is what I have
1. Create a form with two buttons and a picturebox
2. Download the WIA dlls and add references to them (WIA and WIAVideoLib)
3. Drop this code on your code-behind file
private void button2_Click(object sender, EventArgs e)
CommonDialogClass cdcMine = new CommonDialogClass();
Device d = cdcMine.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);
if (d != null)
//get the devide ID
this.DeviceID = d.DeviceID;
//no scanner chosen
CommonDialogClass WiaCommonDialog = new CommonDialogClass();
DeviceManager manager = new DeviceManagerClass();
Device WiaDev = null;
foreach (WIA.DeviceInfo info in manager.DeviceInfos)
if (info.DeviceID == this.DeviceID)
WIA.Properties infoprop = null;
infoprop = info.Properties;
//connect to scanner
WiaDev = info.Connect();
//not very good coding practice. exit the IF when connected
mVid.ImagesDirectory = imageDirectory;
mVid.CreateVideoByWiaDevID(this.DeviceID, pictureBox1.Handle, 1, 1);
mVid is a WiaVideo object that you declare on form load as WiaVideo mVid = new WiaVideo();
The important part here is the imageDirectory variable, which is a string variable that was also instantiated and assigned during form load. If you do not provide a destination directory, it probably won’t run. :p
Then to take a picture
private void button1_Click(object sender, EventArgs e)
Couldn’t be any simpler than that. This part is where you will understand why mVid and imageDirectory were declared during load.
Also, don’t forget to call
before closing the form!
that’s it! any questions, post them as comments here.