Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WIA Scanning via Feeder

Tags:

c#

scanning

wia

WIA Scanning via Feeder

Here is my device properties:

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

Here is my item (page) properties:

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

I got everything running smoothly if I set the "Document Handling Select" to "2". When I set it to "1", and ran it, just before I say item.Transfer() (or item.Transfer(bmp/jpeg/pngGuid)) I get the exception "Value does not fall within the expected range."

This is so annoying, what value? I have googled the web, and I could only find a little information but it isn't much of help.

like image 692
Willem Toerien Avatar asked Aug 16 '11 10:08

Willem Toerien


People also ask

Can I scan through the feeder?

The only way to scan from feeder, is to use "Windows Fax and Scan" program at a computer after place document in feeder. In the "New Scan" window, change "source" to "Document Feeder". Then it will scan from feeder.

How do I scan on WIA?

To install a WIA driver, you'll need to go to the manufacturer's website and download the driver. Once you've downloaded the driver, double-click it and follow the instructions on the screen. After you've installed the driver, restart your computer and then try using Windows Scan again.

What is a WIA scanning device?

Windows Image Acquisition (WIA; sometimes also called Windows Imaging Architecture) is a proprietary Microsoft driver model and application programming interface (API) for Microsoft Windows Me and later Windows operating systems that enables graphics software to communicate with imaging hardware such as scanners, ...

What is the difference between TWAIN and WIA scanning?

In general, when a device supports both TWAIN and WIA, TWAIN is better for scanners and WIA is better for acquiring images from still cameras and video devices. WIA uses a common dialog for all devices, while TWAIN uses a dialog created by the device manufacturer.


1 Answers

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);
        }
    }
like image 137
Matthias Wuttke Avatar answered Sep 19 '22 14:09

Matthias Wuttke