TWAIN is a specification that provides a standard interface for software applications to communicate with hardware devices such as scanners and digital cameras in a device-independent manner. The TWAIN specification is somewhat complex, but there are a number of libraries available to programmers that simplify the process of developing TWAIN-aware applications. These libraries are available as freeware, shareware, and as parts of large commercial imaging packages that cost hundreds of dollars.
MultiTWAIN is a freeware library of routines that simplify the process of acquiring images from TWAIN-compliant devices. The thing that makes MultiTWAIN stand out from other packages available is that, to my knowledge, it is the *ONLY* freeware library for Delphi that supports the acquisition of multiple consecutive images from digital cameras and scanners with automatic document feeders. Previously, Delphi users had to choose between using free software that handles only image at a time versus large, expensive, commercial packages that include this feature among a host of other routines.
MultiTWAIN was not developed from scratch. It is based entirely on a version of Spike McLarty's excellent freeware library EZTWAIN. EZTWAIN is a DLL written in C that provides services to simplify the acquisition of individual images from a TWAIN device. MultiTWAIN represents a version of this code that has been compiled into an OBJ file, then included into a Delphi "unit" file with appropriate headers for the function declarations. Thus, Delphi applications that use MultiTWAIN do *NOT* require the presence of EZTWAIN.DLL or EZTW32.DLL. Additionally, the EZTWAIN C code was modified so as to support acquisition of multiple images.
SYSTEM REQUIREMENTS
MultiTWAIN was developed using Delphi 4, but it should compile correctly under Delphi 3 and 2. The only caveat is that some of the EZTWAIN routines upon which MultiTWAIN relies require parameters in the form of unsigned 32-bit integers. This data type is currently not supported in Delphi 2 or 3, and therefore the code attempts to substitute a 32-bit signed integer in place of this. This is only an issue with a few minor functions, but it's something to keep in mind in case problems come up.
USE
Use of MultiTWAIN is *very* easy. Although a ton of functions are supported, in practice you only need to know about a handful:
* Standard TWAIN access routines:
- TWAIN_SelectSource: displays a dialog box to allow the user to
select a TWAIN device. Accepts an HWND as
an argument, but sending it zero works fine.
- TWAIN_AcquireNative: returns a handle to a device-independent
bitmap (DIB) for the last image acquired (or
the only image, as the case may be). Accepts
two arguments: an HWND and a pixmask. Set
both to zero (I've had problems with my
camera when I specify the proper HWND).
- TWAIN_FreeNative: releases the memory owned by a DIB
* Routines to support acquisition of multiple images
- TWAIN_GetNumDibs: returns the number of images retrieved
- TWAIN_GetDib: returns a handle for the nth image retrieved
- RegisterDibCallback: designate an optional user-defined function
to be called for each image transferred.
Note that unfortunately the function
designated as a callback function *CANNOT* be
an object member function. It MUST be
free-standing.
- UnRegisterDibCallback: tells the system not to call *any* user-
defined callback function
* Delphi support for DIBs
- CopyDIBIntoImage: accepts a handle to a DIB and a TImage, then
renders the DIB into the TImage's canvas
A very short demonstration program is included to demonstrate the use of these functions. It's really quite easy.
CHANGES TO ORIGINAL EZTWAIN CODE
In order to make EZTWAIN.C compile into an OBJ that would be suitable for inclusion into a Delphi unit, some changes had to be made. These included removal of references to any functions in the C run-time library. Specifically, the RTL memset() and memcpy() functions were re-written from scratch to remove reliance on the RTL versions. Also, one function used wsprintf to generate error messages, but I couldn't get it to compile correctly, so I omitted the reference and made the error messages somewhat generic.
Finally, some functions that dealt with floating point numbers were removed and re-implemented in Pascal so as to avoid reliance on C support routines for floating-point numbers.
FINAL REMARKS
Although this software is freeware, I do make one small request: *PLEASE* send me e-mail to let me know if MultiTWAIN meets a programming need you could not have fulfilled elsewhere (or even if you could). I hope to hear from as many users as possible.