使用WIA检测所有可用的扫描仪分辨率 [英] Detect all available scanner resolutions using WIA

查看:330
本文介绍了使用WIA检测所有可用的扫描仪分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用WIA 2.0以编程方式检测指定扫描仪的所有可用分辨率(以dpi为单位)?支持的页面大小如何?有什么想法吗?

解决方案

伪代码: 假设您有设备信息,请连接到它:

var device = deviceInfo.Connect(); 如果设备不为空.....那么你可以得到物品 请注意,项目从设备项目的索引1开始

Item item = device.Items[1]; 一个项目具有各种属性,您可以枚举 例如

foreach (Property prop in item.Properties) { var temp = prop.Name + " " + prop.PropertyID + " " + prop.get_Value(); }

在这种情况下,可以找到可以使用的扫描仪支持的最大DPI. 水平光学分辨率"(属性ID:3090) 垂直光学分辨率"属性ID:3091

..但是,如果检查属性枚举,您将发现没有任何信息可以告诉您所有可用DPI设置的最小值或列表. ..现在我也找不到任何东西.... 但是我确实找到了发现最小DPI的方法. 您可能知道WIA的意图,该枚举允许您设置扫描类型,例如颜色,灰度等(属性ID:6146)

var currentIntent = item.Properties.get_Item("6146"); // set to colour currentIntent.set_Value(WiaImageIntent.ColorIntent);

..但是,您也可以通过这种方式设置WIA图像偏差(最大质量或最小尺寸) 这不是通过图像意图枚举,而是通过对相应的值进行或运算来完成

// set minimum size as WIA bias var intent = (int)item.Properties.get_Item("6146").get_Value(); item.Properties.get_Item("6146").set_Value(intent | 0x00010000);

http://msdn.microsoft. com/en-us/library/ms630190%28v = vs.85%29.aspx

如果您现在查看DPI(假设以前的DOI并非最低)

var dpiHorizontal = item.Properties.get_Item("6147").get_Value(); var dpiVertical = item.Properties.get_Item("6148").get_Value(); ..您应该会看到DPI现在已设置为最低(以进行最小尺寸扫描)

一个大警告.

一旦设置了偏差(最小尺寸或最大质量),您设置的任何以前的DPI值都会更改(图像尺寸等各种其他属性也将发生变化–会进行广泛的更改).

..因此,如果您想保持控制状态,我建议只找到一次最低dpi,然后将其存储在配置中;或者,如果每次都这样做,则丢弃该项目(在获得最低DPI之后)并使用一个新项目.没有偏见.

..因此,您现在有了最大和最小DPI值–如何获取列表?

..我再也不知道..但是 您可能会列出合理的DPI值" 例如75、100、150、200、300、600、1200、2400 由于(取决于扫描仪的分辨率)这些是支持的受欢迎"值 ..根据最大/最小DPI值,您知道哪些流行"值可能值得尝试.

..并在设置DPI时通过try/catch进行操作

例如

try { item.Properties.get_Item("6147").set_Value(myDPI); // horizontal DPI item.Properties.get_Item("6148").set_Value(myDPI); // vertical DPI } catch { // not supported so have some logic where try a different popular value }

我看到我使用的一台扫描仪出现这种类型的问题–仅因为DPI在最大/最小限制之内并不意味着它受到支持. 尽管许多扫描仪WIA驱动程序支持100、100 DPI,但该驱动程序不提供75,75 DPI或150,150 DPI 这种方法令人讨厌又笨拙,但是可以(再次可以执行一次,遍历受欢迎的"DPI"值列表,尝试设置它们,然后留下扫描仪支持的DPI设置列表.

为简单起见,这些伪代码示例假定为垂直&水平DPI可能都设置为相同的值..并非所有扫描仪都如此!

How can I programmatically detect all available resolutions (in dpi) for a specified scanner using WIA 2.0? What about page sizes supported? Any ideas?

解决方案

Pseudo code: Assume you have device info, connect to it:

var device = deviceInfo.Connect(); if device is not null….. then you can get the Item Note that items begin at index 1 for device items

Item item = device.Items[1]; An Item has various properties which you can enumerate e.g.

foreach (Property prop in item.Properties) { var temp = prop.Name + " " + prop.PropertyID + " " + prop.get_Value(); }

In this case to find Maximum DPI supported by your scanner you could use. "Horizontal Optical Resolution" (property id: 3090) "Vertical Optical Resolution" property id: 3091

.. However if you examine the properties enumeration you will see there is nothing to tell you the minimum or list of all available DPI settings. .. Now I could not find anything either…. However I did find a way of discovering the minimum DPI… You may be aware of WIA intent, the enumeration allows you to set scanning type e.g. colour, grey scale etc. (property id: 6146)

var currentIntent = item.Properties.get_Item("6146"); // set to colour currentIntent.set_Value(WiaImageIntent.ColorIntent);

.. However you can also set WIA image bias in this way (to either maximum quality or minimum size) This is not via image intent enumeration but is done by OR ing the appropriate values

// set minimum size as WIA bias var intent = (int)item.Properties.get_Item("6146").get_Value(); item.Properties.get_Item("6146").set_Value(intent | 0x00010000);

http://msdn.microsoft.com/en-us/library/ms630190%28v=vs.85%29.aspx

And if you now look at the DPI (assuming previously DOI was not actually at minimum)

var dpiHorizontal = item.Properties.get_Item("6147").get_Value(); var dpiVertical = item.Properties.get_Item("6148").get_Value(); .. you should see that DPI is now set to it’s lowest (to give minimum size scan)

A big warning.

As soon as you set bias (be it minimum size or maximum quality) any previous DPI values you set are changed (as are various other properties for image dimensions etc – it makes wide ranging changes).

.. So, if you want to stay in control I suggest just finding minimum dpi once and storing it in configuration – Or if you do it each time, discard that item (after getting minimum DPI) and use a new item with no bias set.

.. So you now have max and min DPI values – how to get a list?

.. Again I know of no way .. but You could have a list of "sensible DPI values" e.g. 75, 100, 150, 200, 300, 600, 1200, 2400 As (depending on scanner resolution) these are "popular" values to support .. Depending on your max / min DPI values you know what "popular" values may be worth trying.

.. and when setting DPI do it via try / catch

e.g.

try { item.Properties.get_Item("6147").set_Value(myDPI); // horizontal DPI item.Properties.get_Item("6148").set_Value(myDPI); // vertical DPI } catch { // not supported so have some logic where try a different "popular" value }

I see this type of issue with one scanner I use – just because a DPI is within the max / min limits does not mean it is supported. Although many scanners WIA drivers support 100, 100 DPI, this one does not but does provide 75,75 DPI or 150,150 DPI This approach is nasty and kludgy but works (and again you could just do this once, run through your list of popular "DPI" values, try and set them, and be left with a list of which DPI settings your scanner supports.

For the sake of simplicity sake these pseudocode examples assume vertical & horizontal DPI may both be set to same value .. this may not be the case with all scanners!

这篇关于使用WIA检测所有可用的扫描仪分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆