WIA silverlight 扫描仪集成

发布于 10-06 06:05 字数 1072 浏览 11 评论 0原文

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

                }

            }            
        }

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

                }

            }            
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄意2024-10-13 06:05:00

您实际上不需要处理设备命令来扫描文档。相反,您需要使用设备对象下的第一个设备项。这是一个本身有效的小示例,没有故障检查,以便于阅读。

//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 兼容的扫描仪,您可以从 此页...适用于.Net Framework 2.0,C#。也许它在您的项目中会派上用场,您只需几行代码即可完成,包括设置基本属性。 :)

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. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文