2011-01-28 25 views
4

有一個我一直用來遠程控制數碼相機的舊程序,以便自動拍照並將其傳輸到PC。程序基於WIA,據我所知,它最初是在Windows XP上設計和使用的。WIA:device.ExecuteCommand(CommandID.wiaCommandTakePicture);返回null

最近從檔案中拿出來,一直試圖讓它在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圖像採集之後的事件。已經嘗試過這一點,並沒有提出任何事件。

+1

無法找到解決方案,所以我選擇安裝Windows 7的XP Mode並在VM中運行該程序。 – Thingfish 2011-01-28 14:40:48

回答

0

以我的經驗,WIA有很多古怪。我也努力與Item item = device.ExecuteCommand(CommandID.wiaCommandTakePicture);返回的null,雖然我在Windows 7中開發,我的機器是32位。

解決方案在我的機器上正在聽原始問題中提到的事件。如果不工作,嘗試註冊使用通配符的設備ID的事件:

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

我還發現,我需要重新註冊的每個設備命令後的事件,否則將停止觸發。