How do I enumerate resolutions supported via TWAIN

我的梦境 提交于 2019-12-08 00:08:44

问题


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

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?


回答1:


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).

You must specify that the pointer points to TW_UNIT32 values BEFORE reading the value.

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];

or

TW_UINT32 res = *((TW_UINT32*)(en->ItemList + i * 4));


来源:https://stackoverflow.com/questions/7727754/how-do-i-enumerate-resolutions-supported-via-twain

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