Set page size using WIA (with scanner)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 06:56:32
Piotr Justyna

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.

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