简体   繁体   中英

Take a picture from Integrated Laptop Camera using C#

I am trying to write one portion of my huge C# program that allows me to capture one picture from the integrate camera in the laptop. I have already done my research and i notice that there are 2 ways to do this via WIA and DirectShow. I am trying the easier one : WIA. I am working on a Windows 7 32 bit machine running VS 2010 .Net 4.0 . I am trying to run the following example i found on the web, which is exactly what i want and experienced several errors with regards to it.

http://www.c-sharpcorner.com/uploadfile/yougerthen/610262008064756am/6.aspx

I have added the necessary reference


using System.Windows.Forms;
using Microsoft.Win32;
using WIA;

Majority of the errors are like the following : Interop type 'WIA.CommonDialogClass' cannot be embedded. Use the applicable interface instead. Interop type 'WIA.CommandID' cannot be embedded. Use the applicable interface instead.

Any help provided will be greatly appericiated.

I found a solution that just suite my needs without going through DirectShow. It is done using the avicap32.dll library. Those who want to implement something similar as mine. Can have a look at this link http://www.timvw.be/wp-content/code/csharp/testavicap32.zip . just compile it with VS 2010, it works. Just learn, understand and tweak the example to suite to your needs.

Try this:

WIA.CommonDialog wiaDiag = new WIA.CommonDialog();

Creating COM interfaces with the new operator is allowed. You need to prefix the namespace name because CommonDialog is ambiguous with the Winforms CommonDialog class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM