For the past two days, I have been looking for a way to capture a webcam image using C #. I am new to C # and I DO NOT want to use external third-party libraries, so I found two nice ways, but both return almost the same error. I could not get them to work, so it would be very nice if you could help me get one of them to flee or help me find an alternative.
So, the first way I found is to use Windows WIA. I found the following code:
CommonDialogClass dialog = new CommonDialogClass(); Device camera = dialog.ShowSelectDevice(WiaDeviceType.CameraDeviceType, true, false); // take the photo Item item = camera.ExecuteCommand(CommandID.wiaCommandTakePicture); ImageFile image = (ImageFile)item.Transfer(FormatID.wiaFormatJPEG); // filename and saving image.SaveFile("Test.jpg");
this code seems to be what I'm looking for, but I cannot run it because the following error appears in the second line:
Exception from HRESULT: 0x80210015
The second way I found is to use Avicap32.dll with the following example:
http:
but I get this code:
Image image = ((CaptureDevice)cboDevices.SelectedItem).Capture(); image.Save(@"c:\capture.png", ImageFormat.Png);
the following exception: NullReferenceException: The object reference is not set to the object instance.
I think both solutions cause problems because they cannot find my camera, but I can use my camera in skype without any problems.
Viktor Kirilov
source share