JImageConnect.com Skip Navigation LinksHome . Tech Support . API Samples

Skip Navigation Links.

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.

/* Instantiate the TWAIN engine */
TwainConnect twainconnect = new TwainConnect();
/* Instantiate the direct show engine */
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 getAvailableSources() 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:

  1. Implement the TwainEventListener class at least. There are other interfaces to help with error processing.
  2. Register yourself with the TwainConnect engine using your TwainConnect instance (or the “this” pointer in many cases) as a listener.
  3. Invoke the void acquire(String sourceName) method from the TwainConnect class with a valid source name
  4. Retrieve the BufferedImage during the void twainImageCaptured(TwainEvent c) event.
  5. For and ADF or multiple pages twainImageCaptured will be called one time for each page.
// Step One
class JTwacker extends JFrame implements TwainEventListener, DirectShowEventListener{…}
  // Step Two
  // DO NOT FORGET TO ADD THE LISTENER

  twainconnect.addTwainListener(this);

  directShowConnect.addDirectShowListener(this);

  // Step Three
  ...

  twainconnect.acquire(sourcName);
  ...

  directShowConnect.acquire(type.getSourceName());
  }
  // Step Four
  /* As defined by TwainEventListener */
  ...

  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 logging.properties 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 -Djava.util.logging.config.file=logging.properties

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 -Xmsn and -Xmxn arguments. For large images we have found good luck with -Xms256m -Xmx512m. There are consequences to these values and you will need to profile your desktop to confirm these settings.