开发者

WIA silverlight Scanner integration

开发者 https://www.devze.com 2023-01-28 04:47 出处:网络
I am new to silverlight , and I am experimenting with wia scanner integration. I know usng WIA.CommonDialog , showacquireimage() I can retrieve an image from the scanner. I am trying to access the dev

I am new to silverlight , and I am experimenting with wia scanner integration. I know usng WIA.CommonDialog , showacquireimage() I can retrieve an image from the scanner. I am trying to access the device directly and execute the scan command to avoid user interaction.

I am able to connect to the device. But the only command avail开发者_如何转开发able from the scanner is synchronize. I am trying to use the ExecuteCommand on the device object, but I am not sure what command to use. Any direction will be appreciated.

        using (dynamic DeviceManager1 = AutomationFactory.CreateObject("WIA.DeviceManager"))
        {
            var deviceInfos = DeviceManager1.DeviceInfos;
            for(int i= 1;i<=deviceInfos.Count;i++)
            {
                //check if the device is a scanner
                if (deviceInfos.Item(i).Type.ToString() == "1")
                {
                    var IDevice = deviceInfos.Item(i).Connect();
                    deviceN.Text = IDevice.Properties("Name").Value.ToString();

                    var dv = IDevice.Commands;
                    for (int j = 0; j <= dv.Count; j++)
                    {

                        deviceN.Text += " " + dv.Item(i).CommandID.ToString() + " " + dv.Item(i).Description.ToString();
                    }

                }

            }            
        }


You don't really need to deal with the device commands to scan the document. Instead you need to use the first device item under the device object. Here is a little example which works in itself, without failure checks for easier readability.

//using WIA;

bool showProgressBar = false;

DeviceManager deviceManager = new DeviceManagerClass();

foreach(DeviceInfo info in deviceManager.DeviceInfos)
{
    if(info.Type == WiaDeviceType.ScannerDeviceType)
    {
        Device device = info.Connect();

        ImageFile imageFile = null;

        Item deviceItem = null;

        //Read through the list of items under the device...
        foreach(Item item in device.Items)
        {
            //Pick the very first one!
            deviceItem = item;
            break;
        }

        if(showProgressBar == true)
        {
            //Scan without GUI, but display the progress bar dialog.
            CommonDialogClass commonDialog = new CommonDialogClass();
            imageFile = (ImageFile)commonDialog.ShowTransfer(deviceItem, FormatID.wiaFormatBMP, false);
        }
        else
        {
            //Scan without GUI, no progress bar displayed...
            imageFile = (ImageFile)deviceItem.Transfer(FormatID.wiaFormatBMP);
        }

        imageFile.SaveFile("C:\\image.bmp");
    }
}

Before scanning (but after you connected to the device item), you probably need to set various device properties to select the scanning resolution, color depth and other things if the defaults are not good enough for your needs.

Not long ago I made an easy to use class to operate WIA-compatible scanners, you can download it from this page... It's for .Net Framework 2.0, C#. Maybe it could come handy in your project, you would be done with a few lines of code including setting the basic properties. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号