4

有一个我一直用来远程控制数码相机的旧程序,以便自动拍照并将它们传输到 PC。该程序基于 WIA,据我所知,它最初是在 Windows XP 上设计和使用的。

最近将它从档案中取出,并一直试图让它在使用相同相机的 64 位 Windows 7 上工作。找到相机并触发捕获工作没有问题。但是在执行此行时:

//device of type WIA.Device
Item item = device.ExecuteCommand(CommandID.wiaCommandTakePicture);

返回 null,让我没有图像参考来传输。一直在寻找解决方案,但一直无法提出任何建议。找到另一个 QA 站点,其中一个答案建议使用:

//manager of type WIA.DeviceManager, device of type WIA.Device
manager.RegisterEvent(EventID.wiaEventItemCreated, device.DeviceID);
manager.OnEvent += new _IDeviceManagerEvents_OnEventEventHandler(manager_OnEvent);

在图像捕获后,人们会收到包含 itemID 的事件。已经尝试过了,并且没有引发任何事件。

4

1 回答 1

0

根据我的经验,WIA 有很多奇怪之处。我也为null返回的Item item = device.ExecuteCommand(CommandID.wiaCommandTakePicture);问题而苦苦挣扎,虽然我在 Windows 7 中开发,但我的机器是 32 位的。

在我的机器上,解决方案是监听原始问题中提到的事件。如果这不起作用,请尝试使用通配符设备 ID 注册事件:

manager.RegisterEvent(EventID.wiaEventItemCreated, Miscellaneous.wiaAnyDeviceID);
device.ExecuteCommand(CommandID.wiaCommandTakePicture);

我还发现每次设备命令后都需要重新注册事件,否则会停止触发。

于 2011-01-30T11:08:51.370 回答