【问题标题】:WIA silverlight Scanner integrationWIA silverlight 扫描仪集成
【发布时间】:2011-05-20 10:29:53
【问题描述】:

我是 silverlight 新手,我正在尝试使用 wia 扫描仪集成。我知道使用 WIA.CommonDialog , showacquireimage() 我可以从扫描仪中检索图像。我正在尝试直接访问设备并执行扫描命令以避免用户交互。

我能够连接到设备。但扫描仪唯一可用的命令是同步。我正在尝试在设备对象上使用 ExecuteCommand,但我不确定要使用什么命令。任何方向将不胜感激。

        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();
                    }

                }

            }            
        }

【问题讨论】:

    标签: silverlight wia image-scanner


    【解决方案1】:

    您实际上不需要处理设备命令来扫描文档。相反,您需要使用设备对象下的第一个设备项。下面是一个小例子,它本身就可以工作,没有失败检查以便于阅读。

    //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");
        }
    }
    

    在扫描之前(但在您连接到设备项之后),如果默认设置不足以满足您的需求,您可能需要设置各种设备属性以选择扫描分辨率、颜色深度等。

    不久前我做了一个易于使用的类来操作WIA兼容的扫描仪,你可以从this page下载它...它适用于.Net Framework 2.0,C#。也许它可以在您的项目中派上用场,您只需几行代码就可以完成,包括设置基本属性。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-01
      • 1970-01-01
      • 2015-12-18
      相关资源
      最近更新 更多