Monday, April 21, 2008

WIA Scanning without user interaction

WiaClass wiaManager = null; // WIA manager COM object
CollectionClass wiaDevs = null; // WIA devices collection COM object
ItemClass wiaRoot = null; // WIA root device COM object
CollectionClass wiaPics = null; // WIA collection COM object
ItemClass wiaItem = null; // WIA image COM object
try {
wiaManager = new WiaClass(); // create COM instance of WIA manager
wiaDevs = wiaManager.Devices as CollectionClass; // call Wia.Devices to get all devices
if( (wiaDevs == null) (wiaDevs.Count == 0) )
{
MessageBox.Show( this, "No WIA devices found!", "WIA", MessageBoxButtons.OK, MessageBoxIcon.Stop );
Application.Exit();
return;
}
object selectUsingUI = System.Reflection.Missing.Value; // = Nothing
wiaRoot = (ItemClass) wiaManager.Create( ref selectUsingUI ); // let user select device
if( wiaRoot == null ) // nothing to do
return;
((Item)wiaRoot.Children[0]).Transfer("C:\\a.tmp", false);
....
Note: Tnx to unknown author of "WIA Scripting and .Net" at codeproject.com

5 comments:

Mark said...

Now you grab the first picture that was in the queue, but you don't take a new picture?
Do you know how to take a new picture without using user interaction and WIAVideo?

Me said...

Hi Mark,

I have done this for a project I have worked on for a long time ago. I am afraid that I cannot help you now because I don’t have any scanner to test on. Sorry.

Revz said...

is there a way to set WiaIntent.ImageTypeColor in WIA Scanning without user interaction ?

Mijalko said...

Sorry Revz

It was long time ago...

Revz said...

This was much easier with WIA Automation.