【问题标题】:How can I get MICR string from scanner by using TWAIN driver如何使用 TWAIN 驱动程序从扫描仪获取 MICR 字符串
【发布时间】:2014-08-20 05:59:24
【问题描述】:

我正在编写一些用于从检查中提取 MICR 字符串的 C# 代码。

我的扫描仪是 Cannon DR-850M,它支持 MICR 阅读器。

它可以在自己的扫描程序上读取 MICR 字符串。但我需要使用 TWAIN 自己制作。

我可以使用 TWAIN 驱动程序扫描我的程序中的图像。但是,我找不到如何获取 MICR 字符串。

在 TWAIN 中是否有访问扫描仪的 MICR 阅读器的功能?还是别的什么?


我发现 MICR 数据位于“扩展图像信息”中。感谢您的回答。

还有一点问题。

这是我的代码。

// Twain DLL Wrapper
[StructLayout(LayoutKind.Sequential, Pack = 2)]
internal class TwInfo
{                                   // TW_INFO
    public short InfoID;
    public short ItemType;
    public short NumItems;
    public short CondCode;
    public int Item;
}

[StructLayout(LayoutKind.Sequential, Pack = 2)]
internal class TwExtImageInfo
{                                   // TW_EXTIMAGEINFO
    public int NumInfos;
    [MarshalAs(UnmanagedType.Struct, SizeConst = 1)]
    public TwInfo Info;
}

//Application
public void GetExtendedImageInfo()
    {
        TwRC rc;
        TwExtImageInfo exinf = new TwExtImageInfo();

        exinf.NumInfos = 1;
        exinf.Info = new TwInfo();
        exinf.Info.InfoID = (short)TwEI.BARCODETEXT;

        rc = DSexfer(appid, srcds, TwDG.Image, TwDAT.ExtImageInfo, TwMSG.Get, exinf);

        // Here's What I want to know.
        IntPtr itemPtr = new IntPtr(exinf.Info.Item);  
        string str = Marshal.PtrToStringAnsi(itemPtr); // It returns weird value.
    }

// Here's result
exinf.Info.CondCode : 0 (short)
exinf.Info.InfoID   : 4610 (short)
exinf.Info.Item : 36962876 (int)  // what's that?
exinf.Info.ItemType : 12 (short)
exinf.Info.NumItems : 4 (short)
exinf.NumInfos      : 1 (int)

我从 TWAIN 获得了这些值。

但是不知道exinf.Info.Item是什么值

在示例应用程序中,它显示正确的 MICR 字符。但我自己的返回值很奇怪。

我能得到一些帮助吗?

【问题讨论】:

  • 不要回答问题并在其标题中添加“已解决”。在下面的“您的答案”部分中发布答案。然后使用左侧的绿色勾号接受它。
  • 谢谢!欢迎来到 SO。

标签: c# twain micr


【解决方案1】:

已解决

我只是错过了使用 GlobalLock 作为指针。

这是代码。

public string GetExtendedImageInfo()
    {
        TwRC rc;
        TwExtImageInfo exinf = new TwExtImageInfo();

        exinf.NumInfos = 1;
        exinf.Info = new TwInfo();
        exinf.Info.InfoID = (short)TwEI.BARCODETEXT;

        rc = DSexfer(appid, srcds, TwDG.Image, TwDAT.ExtImageInfo, TwMSG.Get, exinf);

        StringBuilder strItem = new StringBuilder(255);
        IntPtr itemPtr = new IntPtr(exinf.Info.Item);
        IntPtr dataPtr = GlobalLock(itemPtr);
        string str = Marshal.PtrToStringAnsi(dataPtr);
        GlobalUnlock(itemPtr);
        GlobalFree(itemPtr);

        return str;
    }

【讨论】:

    猜你喜欢
    • 2015-05-02
    • 1970-01-01
    • 2019-01-28
    • 2012-05-05
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多