使用WIA设置页面大小(用扫描仪) [英] Set page size using WIA (with scanner)
问题描述
我使用WIA获得来自用C#扫描的图像。我可以扫描的文件,但我不能设置页面大小正确,它总是默认为A4,我需要用信函或法律的时候。
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.
我试图与WIA_DPS_PAGE_SIZE属性,但是当我尝试设置的值,我总是得到一个错误,该值在间隔(尝试了很多可能值)。
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).
我wan't到能够使用WIA_DPS_PAGE_SIZE = WIA_PAGE_AUTO(自动页面大小),但我不能在网上找到与此相关的任何东西。
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!
推荐答案
我知道这可能是为时已晚,以真正帮助你这一说法,但它有可能成为以备将来参考。要更改扫描的项目属性使用这样的code:
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);
}
这意味着,扫描的文件将是大小 A4 ,尺寸为629 x 876。
This means that scanned document will be size A4 with dimensions 629 x 876.
这篇关于使用WIA设置页面大小(用扫描仪)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!