WIA通过馈线扫描

时间:2011-08-16 10:51:25

标签: c# wia scanning

通过馈线进行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))之前我得到异常“值不在预期范围内”。

这太烦人了,有什么价值?我用谷歌搜索了网页,我只能找到一些信息,但它没有多大帮助。

1 个答案:

答案 0 :(得分:8)

我认为你必须将设备属性“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);
        }
    }