使用 WIA 设置页面尺寸(带扫描仪)

发布于 2024-08-21 08:07:35 字数 265 浏览 10 评论 0原文

我正在使用 WIA 通过 C# 从扫描仪获取图像。我可以扫描纸张,但无法正确设置页面尺寸,它始终默认为 A4,有时我需要使用 Letter 或 Legal。

我尝试使用 WIA_DPS_PAGE_SIZE 属性,但是当我尝试设置一个值时,我总是收到错误,该值超出了间隔(尝试了很多可能的值)。

我不希望能够使用 WIA_DPS_PAGE_SIZE = WIA_PAGE_AUTO (用于自动页面大小),但我在网络上找不到与此相关的任何内容。

有谁知道解决方案吗?谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一场信仰旅途 2024-08-28 08:07:35

我知道这可能为时已晚,无法真正帮助您,但它可能会为将来的参考提供方便。要更改扫描项目属性,请使用以下代码:

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);
}

这意味着扫描文档的尺寸为 A4,尺寸为 619 x 876。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文