吐温问题:是否可以从送纸器仅扫描一份文档?

发布于 2024-08-01 17:20:29 字数 526 浏览 5 评论 0原文

我正在使用 http://www.codeproject.com/KB/dotnet/ 中的代码twaindotnet.aspx

我遇到了问题,因为 twain 仅在扫描进纸器中的所有文档后才返回控制权。 如果我扫描 20 个或更多文档,这会导致内存使用量较高。

我想到一次只从送纸器扫描一个文档并保存图像并再次循环调用 api。

我将 cap_xfercount 设置为 1,但这似乎没有帮助:

    TwCapability cap = new TwCapability(TwCap.XferCount, 1);
    rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);

我需要做什么才能从送纸器扫描一份文档? 任何建议表示赞赏。

I am playing with the code from http://www.codeproject.com/KB/dotnet/twaindotnet.aspx

I am having a problem because twain returns control only after all documents in feeder are scanned. This leads to high memory usage if I scan 20 or more documents.

I thought of scanning just one document at a time from the feeder and saving the image and calling the api again in a loop.

I am setting cap_xfercount to 1 but this does not seem to help:

    TwCapability cap = new TwCapability(TwCap.XferCount, 1);
    rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);

What do I need to do to scan just one document from the feeder?
Any suggestions appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无声无音无过去 2024-08-08 17:20:29

功能的顺序很重要,请参阅此文档 www.twain.org/docs/CapOrderForWeb。

编辑:

这些是解决方案中的一些代码片段

设置自动进纸

capFeederEnabled = _twEntities.GetCapability(TwCap.FeederEnabled, (short)1);
TwRC rc = DScap(_applicationId, _sourceId, TwDG.Control, TwDAT.Capability, TwMSG.Set, capFeederEnabled);

TwCapability cap = _twEntities.GetCapability(TwCap.XferCount, 1);
rc = DScap(_applicationId, _sourceId, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);

,然后当发送 Twain 窗口消息时

rc = DSixfer(_applicationId, _sourceId, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, ref hbitmap);
rc = DSpxfer(_applicationId, _sourceId, TwDG.Control, TwDAT.PendingXfers, TwMSG.EndXfer, pxfr);

最终重置扫描仪以获取下一个文档

rc = DSpxfer(_applicationId, _sourceId, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, pxfr);

The order of the cababilities is important, see this doc www.twain.org/docs/CapOrderForWeb.

EDIT:

These are some code fragments from a solution

Setup the auto feed

capFeederEnabled = _twEntities.GetCapability(TwCap.FeederEnabled, (short)1);
TwRC rc = DScap(_applicationId, _sourceId, TwDG.Control, TwDAT.Capability, TwMSG.Set, capFeederEnabled);

TwCapability cap = _twEntities.GetCapability(TwCap.XferCount, 1);
rc = DScap(_applicationId, _sourceId, TwDG.Control, TwDAT.Capability, TwMSG.Set, cap);

and then when the when the Twain Window Message is sent

rc = DSixfer(_applicationId, _sourceId, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, ref hbitmap);
rc = DSpxfer(_applicationId, _sourceId, TwDG.Control, TwDAT.PendingXfers, TwMSG.EndXfer, pxfr);

finally reset the scanner for the next document

rc = DSpxfer(_applicationId, _sourceId, TwDG.Control, TwDAT.PendingXfers, TwMSG.Reset, pxfr);
花开雨落又逢春i 2024-08-08 17:20:29

抱歉,我对 twaindotnet 项目不熟悉,但我确实有很多通过 TWAIN 扫描文档的经验。

首先要注意的是:并非所有文档进纸器都可以以单页模式进纸; 一些重要的扫描仪系列在启动后总是扫描进纸器中的所有内容。 而且,无论标准如何规定,相当多的 TWAIN 驱动程序都不会遵守 XFERCOUNT=1。

如果您尝试通过强制扫描仪扫描“一页作业”来解决问题,您将仅限于恰好支持该功能的(不确定的)扫描仪集。 TWAIN 标准只是不需要此功能。 (但是,是的 - CAP_AUTOSCAN=FALSE 和 XFERCOUNT=1 将是尝试的组合。)

有一个更好的解决方案(时间和耐心允许) - 听起来你想要做的是在每个图像到达时处理和处理它,而不是将它们全部收集在内存中。 弄清楚如何让 TWAIN 库在每个图像到达时将其交给您(或将其写入文件),而不是将它们堆叠在内存中,您将拥有一个适用于所有文档馈送扫描仪的解决方案。 而且对于大多数扫描仪来说,它的扫描速度也会快得多......

I'm sorry that I'm not familiar with the twaindotnet project, but I do have a lot of experience with document scanning through TWAIN.

First a note: Not all document feeders can feed in single-page mode; some important scanner families always scan everything in the feeder once started. And, quite a few TWAIN drivers won't honor XFERCOUNT=1, no matter what the standard says.

If you try to solve the problem by forcing the scanner to scan "one page jobs", you will be limited to the (indeterminate) set of scanners that happen to support that. The TWAIN standard just doesn't require this feature. (But yes - CAP_AUTOSCAN=FALSE and XFERCOUNT=1 would be the combo to try.)

There is a better solution (time & patience permitting) - It sounds like what you want to do is process and dispose of each image as it arrives, instead of collecting them all in memory. Figure out how to get your TWAIN library to hand you each image (or write it to a file) as it arrives instead of stacking them up in memory, and you'll have a solution that works with all document-feeding scanners. And it will scan quite a bit faster with most scanners, too...

书间行客 2024-08-08 17:20:29

这是一个供料器问题。 您是否尝试过将馈线启用功能设置为 false?

编辑:

看起来 CAP_AUTOFEED 是要走的路。 根据 TWAIN 2.0 规范

CAP_AUTOFEED
描述
如果为 TRUE,则在获取从每页协商捕获的帧数后,源将自动从文档进纸器送入下一页。 CAP_FEEDERENABLED
必须为 TRUE 才能使用此功能。
应用
将功能设置为 TRUE 可启用源的自动馈送过程,或设置为 FALSE 可禁用它。
每次传输完成后,检查TW_PENDINGXFERS。 计数以确定是否
源有更多图像要传输。 -1 表示有更多图像要传输,但确切的值
数量未知。
CAP_FEEDERLOADED 指示 Source 的 feeder 是否已加载。 (自动进给
只要此功能为 TRUE,该过程就会继续。)

This is a feeder issue. Have you tried setting the feeder enabled capability to false?

EDIT:

Looks like CAP_AUTOFEED is the way to go. According to the TWAIN 2.0 specification:

CAP_AUTOFEED
Description
If TRUE, the Source will automatically feed the next page from the document feeder after the number of frames negotiated for capture from each page are acquired. CAP_FEEDERENABLED
must be TRUE to use this capability.
Application
Set the capability to TRUE to enable the Source’s automatic feed process, or FALSE to disable it.
After the completion of each transfer, check TW_PENDINGXFERS. Count to determine if the
Source has more images to transfer. A -1 means there are more images to transfer but the exact
number is not known.
CAP_FEEDERLOADED indicates whether the Source’s feeder is loaded. (The automatic feed
process continues whenever this capability is TRUE.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文