Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

c# - Twain question: is it possible to scan just one document from feeder?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...