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.
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);
}
}
来源:https://stackoverflow.com/questions/7077020/wia-scanning-via-feeder