Take a picture automatically using a webcam in C# using WIA

大城市里の小女人 提交于 2019-12-05 12:29:49

From what I can see, wiaItem = wiaRoot.TakePicture() is going down the wrong path. Try this:

string imageFileName;
wiaRoot.TakePicture( out takenFileName);
pictureBox1.Image = Image.FromFile(imageFileName);

TakePicture saves a picture to a file, and returns the new file's name as an output parameter.

Edit per your comment - are you using the "windows 7 version" of WiaLib? If so, try something like this:

var manager = new DeviceManagerClass();
Item wiaItem;
Device device = null;
foreach (var info in manager.DeviceInfos)
{
    if (info.DeviceID == DESIRED_DEVICE_ID)
    {
        device = info.Connect();
        wiaItem = device.ExecuteCommand(CommandID.wiaCommandTakePicture);
    }
}

where you use the ExecuteCommand with the well known guid (also exposed from the COM interop wrapper) rather than TakePicture. It worked for my webcam, in any case.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!