Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set page size using WIA (with scanner)

I'm using WIA to acquire images from a scanner with C#. I can scan the papers, but I can't set up the page size correctly, it always defaults to A4 and I need to use Letter or Legal sometimes.

I tried with the WIA_DPS_PAGE_SIZE property, but when I try to set a value, I always get an error, that the value is out of the interval (tried a lot of possible values).

I wan't to be able to use WIA_DPS_PAGE_SIZE = WIA_PAGE_AUTO (for automatic page size), but I can't find anything on the web related to this.

Does anyone know a solution? thanks!

like image 821
Salvador Sarpi Avatar asked Feb 11 '10 15:02

Salvador Sarpi


People also ask

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 compliant scanner?

What is WIA. WIA (Windows Image Acquisition), introduced by Microsoft since Window Me, is the driver platform delivered with the Windows OS, including Windows 7, Windows 8, etc. It enables applications to acquire images from all kinds of digital cameras and scanners.


1 Answers

I know this is probably too late to actually help you with that, but it may become handy for future reference. To change scanned items properties use such code:

WIA.CommonDialog wiaDlg;
WIA.Device wiaDevice;
WIA.DeviceManager wiaManager = new DeviceManager();

wiaDlg = new WIA.CommonDialog();
wiaDevice = wiaDlg.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false);

foreach (WIA.Item item in wiaDevice.Items)
{
    StringBuilder propsbuilder = new StringBuilder();

    foreach (WIA.Property itemProperty in item.Properties)
    {
        IProperty tempProperty;
        Object tempNewProperty;

        if (itemProperty.Name.Equals("Horizontal Resolution"))
        {
            tempNewProperty = 75;
            ((IProperty)itemProperty).set_Value(ref tempNewProperty);
        }
        else if (itemProperty.Name.Equals("Vertical Resolution"))
        {
            tempNewProperty = 75;
            ((IProperty)itemProperty).set_Value(ref tempNewProperty);
        }
        else if (itemProperty.Name.Equals("Horizontal Extent"))
        {
            tempNewProperty = 619;
            ((IProperty)itemProperty).set_Value(ref tempNewProperty);
        }
        else if (itemProperty.Name.Equals("Vertical Extent"))
        {
            tempNewProperty = 876;
            ((IProperty)itemProperty).set_Value(ref tempNewProperty);
        }
    }

    image = (ImageFile)item.Transfer(WIA.FormatID.wiaFormatPNG);
}

This means that scanned document will be size A4 with dimensions 619 x 876.

like image 99
Piotr Justyna Avatar answered Sep 20 '22 15:09

Piotr Justyna