WIA: device.ExecuteCommand (CommandID.wiaCommandTakePicture); returns null

I have an old program that I use to remotely control a digital camera to automatically take photos and transfer them to a PC. The program is based on WIA and, as I recall, it was originally developed and used in Windows XP.

Recently I left the archives and tried to get it to work on 64-bit Windows 7 using the same camera. Finding a camera and starting capture is no problem. However, when executing this line:

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

null, leaving no reference to the image for transmission. They were looking for a high and low solution, but could not come up with anything. Found another QA site where the answer suggested using:

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

one could receive events containing ItemID after image capture. They tried it, and no event came up.

+4
source share
1 answer

In my experience, WIA has a lot of oddities. I also struggled with null returned by Item item = device.ExecuteCommand(CommandID.wiaCommandTakePicture); , and although I am developing in Windows 7, my machine is 32-bit.

The solution on my machine listens for the event, as indicated in the original question. If this does not work, try registering for the event using the wildcard identifier:

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

I also found that I need to re-register the event after each device command, otherwise it would stop starting.

0
source

Source: https://habr.com/ru/post/1337414/


All Articles