Take a Picture of Persenels with a Digital Camera

2019-05-31 17:07发布

问题:

I Want Create a Win-Form Application Can be Connect to a Digital Camera Attached to My Computer.I Want See a LiveView of Persenels in Computer And Then Take a Picture of Persenels.

How Can I Implement This Action?

What Camera Can I Use?

What Component Or Library Can I Use??

What SDk Tools Can I Use??

Please Help me...

回答1:

You can do this with the Windows Image Acquisition API. Get this started with Project + Add Reference, Browse tab, navigate to c:\windows\system32\wiaaut.dll. That's a COM component, you'll get an interop library for it with interface types in the WIA namespace.

First thing you want to do is get a reference to the camera, use WIA.ShowSelectDevice(). It returns a Device object if there's only one camera attached, a dialog to let the user select if there are more. Like this:

    public static WIA.Device SelectCamera() {
        var dlg = new WIA.CommonDialog();
        try {
            return dlg.ShowSelectDevice(WIA.WiaDeviceType.CameraDeviceType, false, false);
        }
        catch (System.Runtime.InteropServices.COMException ex) {
            if (ex.ErrorCode == -2145320939) return null;
            throw;
        }
    }

That ought to get you started. Check out the code snippets at this MSDN page for more of the thing you can do with the API. Beware that not all cameras allow you do use them interactively when they are attached to the machine. My cheapo point-and-shoot doesn't.