设置TWAIN扫描的分辨率

时间:2017-06-22 07:01:52

标签: c# winforms resolution scanning twain

我在WinForms中创建了一个可以列出所有twain& wia扫描仪,并使用该列表中的所选设备进行扫描。

每当我使用TWAIN扫描而不使用TWAIN用户界面时,我会得到质量不佳的图像。

我的代码基于此处的包装器:https://www.codeproject.com/Articles/1376/NET-TWAIN-image-scanner?msg=1097187#xx1097187xx以及http://www.twain.org/wp-content/uploads/2016/03/TWAIN-2.2-Spec.pdf处的规范

我尝试用dpi设置分辨率,但它没有任何区别。设置上限后,rc总是说“失败”:

TwFix32 f32 = new TwFix32();
f32.FromFloat(300);//value of DPI 

// Set X resolution.
TwCapability capX = new TwCapability(TwCap.XResolution, f32.Whole);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capX);

// Set Y resolution.
TwCapability capY = new TwCapability(TwCap.YResolution, f32.Whole);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capY);

1 个答案:

答案 0 :(得分:1)

它通过创建一个新的构造函数来工作:

public TwCapability(TwCap cap, short sval, TwType twtype)
{
    Cap = (short)cap;
    ConType = (short)TwOn.One;
    Handle = Twain.GlobalAlloc(0x42, 6);
    IntPtr pv = Twain.GlobalLock(Handle);
    Marshal.WriteInt16(pv, 0, (short)TwType.Int16);
    Marshal.WriteInt32(pv, 2, (int)sval);
    Marshal.WriteInt16(pv, 0, (short)twtype);
    Twain.GlobalUnlock(Handle);
}


TwCapability capResx = new TwCapability(TwCap.ICAP_XRESOLUTION, 300, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResx);


TwCapability capResy = new TwCapability(TwCap.ICAP_YRESOLUTION, 300, TwType.Fix32);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, capResy);