How do I instantiate TwainConnect?
Developers should feel free to perform immediate or lazy instantiation on the TwainConnect or JImageConnect
object. There are no JNI calls made during the construction of the object. The first call
to any TwainConnect™ or JImageConnect™ method will actually incur the initial cost of memory creation
and for TWAIN the TWAIN DLL loading.
TwainConnect twainconnect = new TwainConnect();
directShowConnect = new DirectShowConnect();
How do I check if TWAIN is installed programatically?
Your program should check for the availability of TWAIN at start up or at least during
the first time the feature is requested. This state should be cached. Note TwainConnect™
does NOT cache the state of TWAIN. While it is theoretically possible that one could
add a TWAIN device while you application is running, it is not likely. Regardless of
the low likelihood, the TwainConnect™ API will not cache the result. However, feel free
to cache the result for your program; if you do not expect your end-users to be plugging
in devices on the fly.
if (imageEngine.isEngineAvailble()) { ... }
How do I Retrieve Available Twain Data Sources?
The TWAIN API returns the vendor names of all the installed
TWAIN devices. Developers should examine the list and determine if they should expose the
programmatic name of the TWAIN device to end users. Beware the source name(s) may not be
what you expect. The names are vendor specific, not internationalized and may not be misspelled.
If you do not like the source name, you will have to perform some mapping.
As an example, the below code adds the all the available sources names to a UI widget.
Using Java’s Swing™ or Eclipse’s SWT™ is not required. The source names (or single source)
can be stored in any desired collection class and cached.
String[] sources = imageEngine.getAvailableSources();
How do Acquire a TWAIN Image?
TwainConnect™ uses an event driven architecture to acquire the images. Your class must:
- Implement the class at least. There are other interfaces to help with error processing.
- Register yourself with the TwainConnect engine using your TwainConnect instance (or the “this” pointer in many cases) as a listener.
- Invoke the method from the TwainConnect class with a valid source name
- Retrieve the during the event.
- For and ADF or multiple pages will be called one time for each page.
class JTwacker extends JFrame implements TwainEventListener, DirectShowEventListener{…}
twainconnect.addTwainListener(this);
directShowConnect.addDirectShowListener(this);
...
twainconnect.acquire(sourcName);
...
directShowConnect.acquire(type.getSourceName());
}
...
public void twainImageCaptured(TwainEvent event) {
BufferdImage bi = event.getBufferedImage();
...
public void direcShowImageCaptured(DirectShowEvent event) { {
BufferdImage bi = event.getBufferedImage();
}
How do I get more logging details?
Create a local file and place it in the same directory as from where
you are launching the program. For Eclipse create the file in the root direcoty of the project
Then from your command line or from the Eclipse Run Configurations...|(x)- Arguments Tab add the following
Here is a link to a sample logging.properties file you can use in your Eclipse applications
Sample logging.properties file
How do I increase the memory footprint for may application?
See the general documentation here java - the Java application launcher
Specifically the and arguments. For large images we have found good luck with
. There are consequences to these values and you will need to profile your desktop to confirm these settings.
|