WIA Scanning via Feeder

▼魔方 西西 提交于 2019-11-30 13:49:41

I think you have to set the device property "Pages" (ID 3096) from 0 to 1 to prevent the exception. It took me some time to figure this out. Finally, I found this property by comparing the device properties before and after a call to CommonDialogClass.ShowSelectItems.

Here is some code:

    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);
        }
    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!