http://www.mms-computing.co.uk/uk/co/mmscomputing/device/twain/ ist eine Java-API für die TWAIN-Schnittstelle, um etwa einen Scanner anzusteuern. Ein Beispiel ist schnell aufgebaut:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import org.jdesktop.swingx.JXFrame;
import org.jdesktop.swingx.JXImagePanel;
import org.jdesktop.swingx.JXImagePanel.Style;
import uk.co.mmscomputing.device.scanner.Scanner;
import uk.co.mmscomputing.device.scanner.ScannerIOException;
import uk.co.mmscomputing.device.scanner.ScannerIOMetadata;
import uk.co.mmscomputing.device.scanner.ScannerListener;
public class TwainExample
{
@SuppressWarnings("serial")
public static void main( String[] args )
{
final JXImagePanel imagePanel = new JXImagePanel();
imagePanel.setStyle( Style.SCALED_KEEP_ASPECT_RATIO );
final Scanner scanner = Scanner.getDevice();
JXFrame f = new JXFrame( "SSP", true );
Action action = new AbstractAction("Scan") {
@Override public void actionPerformed( ActionEvent e ) {
try { scanner.acquire(); } catch ( ScannerIOException ex ) { }
}
};
f.add( new JButton(action), BorderLayout.PAGE_START );
f.add( imagePanel );
f.setSize( 1000, 700 );
f.setVisible( true );
scanner.addListener( new ScannerListener()
{
public void update( ScannerIOMetadata.Type type, ScannerIOMetadata metadata )
{
if ( ScannerIOMetadata.ACQUIRED.equals( type ) )
imagePanel.setImage( metadata.getImage() );
}
} );
}
}