如何枚举TWAIN支持的分辨率 [英] How do I enumerate resolutions supported via TWAIN
问题描述
我必须通过TWAIN界面枚举扫描仪支持的DPI.
I have to enumerate DPI's supported by scanner via TWAIN interface.
// after Acquire is called...
TW_CAPABILITY twCap;
GetCapability(twCap, ICAP_XRESOLUTION)
if (twCap.ConType == TWON_ENUMERATION) {
pTW_ENUMERATION en = (pTW_ENUMERATION) GlobalLock(twCap.hContainer);
for(int i = 0; i < en->NumItems; i++) {
if (en->ItemType == TWTY_FIX32) {
TW_UINT32 res = (TW_UINT32)(en->ItemList[i*4]);
// print res...
}
那很好,但是输出顺序很奇怪:
That works fine but output sequence is strange:
50 100 150 44 88 176
50 100 150 44 88 176
我确切知道我的扫描仪支持300 DPI,但不会返回此值. 我在这里做错了什么?为什么我可以通过编程设置"300",但为什么没有按顺序返回?
I know exactly that my scanner supports 300 DPI but this value doesn't returned. What I do wrong here? Why "300" is not returned in sequence though I can set it programmatically?
推荐答案
您显示的代码仅获取分辨率的低字节,然后将其转换为整数(指针指向chars,因此该行仅获取char然后将其转换为整数).
The code you shown takes just the lower byte of the resolutions, and then converts it to integer (the pointer points to chars, so the line fetch just a char and then converts it to integer).
在读取值之前,必须指定指针指向TW_UNIT32值.
You must specify that the pointer points to TW_UNIT32 values BEFORE reading the value.
例如数字44是数字300(300 DPI)的低字节
The number 44 for instance, is the lower byte of the number 300 (300 DPI)
以下代码应执行此操作:
The following code should do it:
TW_UINT32 res = ((TW_UINT32*)(en->ItemList))[i];
或
TW_UINT32 res = *((TW_UINT32*)(en->ItemList + i * 4));
这篇关于如何枚举TWAIN支持的分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!