【问题标题】:WIA Scanning via Feeder通过进纸器进行 WIA 扫描
【发布时间】:2011-10-27 23:13:30
【问题描述】:

通过进纸器进行 WIA 扫描

这是我的设备属性:

Document Handling Select = 1 (2 is for flatbed, and 1 is for the feeder.)

这是我的项目(页面)属性:

Horizontal Resolution = 150
Vertical Resolution = 150
Horizontal Extent = 500 (I want to get it first to work, then I'll play with the extents.),
Vertical Extent = 500
Bits Per Pixel = 8
Current Intent = 4

如果我将“文档处理选择”设置为“2”,一切都会顺利进行。当我将它设置为“1”并运行它时,就在我说 item.Transfer()(或 item.Transfer(bmp/jpeg/pngGuid))之前,我得到了异常“值不在预期范围内”。

这太烦人了,有什么价值?我在网上搜索了一下,只能找到一点点信息,但帮助不大。

【问题讨论】:

  • 我玩了更多,我发现我可以使用 feeder 的唯一方法是打开公共对话框询问“项目”。对话框中的方法请求设备。它设置设备和项目中的属性。我看了一眼属性,它看起来和我的问题一样。它有效。一定有什么我没看到的……
  • 我也遇到了同样的问题。 :-( 我假设必须修改另一个设备属性。

标签: c# wia scanning


【解决方案1】:

我认为您必须将设备属性“Pages”(ID 3096)从 0 设置为 1 以防止出现异常。我花了一些时间才弄清楚这一点。最后,我通过比较调用 CommonDialogClass.ShowSelectItems 前后的设备属性找到了这个属性。

这里有一些代码:

    public enum DeviceDocumentHandling : int
    {
        Feeder = 1,
        FlatBed = 2
    }

    const int DEVICE_PROPERTY_DOCUMENT_HANDLING_CAPABILITIES_ID = 3086;
    const int DEVICE_PROPERTY_DOCUMENT_HANDLING_STATUS_ID = 3087;
    const int DEVICE_PROPERTY_DOCUMENT_HANDLING_SELECT_ID = 3088;
    const int DEVICE_PROPERTY_PAGES_ID = 3096;

    public static Property FindProperty(WIA.Properties properties, 
                                        int propertyId)
    {
        foreach (Property property in properties)
            if (property.PropertyID == propertyId)
                return property;
        return null;
    }

    public static void SetDeviceProperty(Device device, int propertyId, 
                                         object value)
    {
        Property property = FindProperty(device.Properties, propertyId);
        if (property != null)
            property.set_Value(value);
    }

    public static object GetDeviceProperty(Device device, int propertyId)
    {
        Property property = FindProperty(device.Properties, propertyId);
        return property != null ? property.get_Value() : null;
    }

    public static void SelectDeviceDocumentHandling(Device device, 
                                DeviceDocumentHandling handling)
    {
        int requested = (int)handling;
        int supported = (int)GetDeviceProperty(device, 
                 DEVICE_PROPERTY_DOCUMENT_HANDLING_CAPABILITIES_ID);
        if ((requested & supported) != 0)
        {
            if ((requested & (int)DeviceDocumentHandling.Feeder) != 0)
                SetDeviceProperty(device, DEVICE_PROPERTY_PAGES_ID, 1);
            SetDeviceProperty(device, 
                   DEVICE_PROPERTY_DOCUMENT_HANDLING_SELECT_ID, requested);
        }
    }

【讨论】:

  • 我已经尝试了上面的代码,但是在设置下面的行时我得到一个异常“值不在范围内”。对象 objValue = FEEDER | WIA_DPS_DOCUMENT_HANDLING_SELECT.DUPLEX; documentHandlingSelect.set_Value(ref objValue);
猜你喜欢
  • 1970-01-01
  • 2018-04-27
  • 2015-12-18
  • 2010-11-14
  • 2016-05-08
  • 1970-01-01
  • 2010-09-05
  • 1970-01-01
  • 2014-01-05
相关资源
最近更新 更多