This open source software project connects the world of java with TWAIN.TWAIN is an application programming interface standard used to access scanners & digital cameras ... .
This package was developed to scan an image in order to turn it into an *.sff file and then fax it. How does it work ? What happens ?
On loading: jtwain.java loads it's C++ counter part, the library jtwain.dll.
jtwain.dll will load "TWAIN_32.DLL" and get a function pointer to the DSM (Data Source Manager) entry point (twain state 2).
If loading was successful jtwain.java creates a new thread that calls nstart in jtwain.cpp.
Due to the fact that twain is signalling events through the OS-dependent event queues, we need to set up an application window including it's wndProc callback function.
After that ninitLib will open the DSM (twain state 3). Now the DSM is ready to handle device specific requests.
The native thread is then entering the event loop and calling jtwain.cbhandleGetMessage whenever it receives an event.
The twain entry function must be called from within the native thread. In order to do that a command can be initiated from arbitrary java threads by calling ntrigger. This will cause the native thread to call jtwain.cbexecute. Two commands can be triggered: 1. Select: The DSM will pop up a select dialog and the user can select a data source. 2. Acquire: The data source will pop up a user dialog that allows the user to set various settings and then either scan or cancel the request. Once an image has been acquired by the twain data source as a DIB (Device Independent Bitmap) a BufferedImage object will be created and the DIB data copied to this BufferedImage. The jtwain object informs the ScannerListeners of the new image.