我有一个用于扫描Web应用程序的uk.co.mmscomputing applet。它适用于Cannon DR-9080C扫描仪。最近我购买了柯达i2600扫描仪,它不能与我的小程序一起使用。当我第一次单击“获取”时,扫描程序会扫描托盘中的所有页面,但是当我加载更多页面并再次单击“获取”时,我会得到“Java停止工作”#34;错误。
我尝试再次设置uk.co.mmscomputing,但没有帮助。
package uk.co.mmscomputing.application.imageviewer;
import java.io.*;
import java.awt.image.*;
import javax.swing.*;
import uk.co.mmscomputing.device.scanner.*;
import uk.co.mmscomputing.device.twain.*;
public class ScannerTab extends ImageTab implements ScannerListener{
static private int no=1;
public ScannerTab(java.util.Properties properties){
super(properties);
}
@Override
protected void setButtonPanel(JPanel gui){
super.setButtonPanel(gui);
try{
Scanner scanner=Scanner.getDevice(); // get a device and set GUI panel up
if(scanner!=null){
gui.add(scanner.getScanGUI());
scanner.addListener(this);
if(scanner instanceof TwainScanner){
TwainIdentity[] list=((TwainScanner)scanner).getIdentities();
for(int i=0;i<list.length;i++){
System.out.println(list[i].toString());
}
}
}
}catch(Exception e){
System.out.println("9\b"+getClass().getName()+".setButtonPanel:\n\t"+e);
}
}
public void update(ScannerIOMetadata.Type type, final ScannerIOMetadata metadata){
if(type.equals(ScannerIOMetadata.ACQUIRED)){ // acquired BufferedImage
final BufferedImage image=metadata.getImage();// make reference copy here to avoid race condition
new Thread(){
@Override
public void run(){
try{
addImage("scan_"+(no++),image);
}catch(Exception e){
System.out.println("9\b"+getClass().getName()+".update:\n\t"+e);
System.err.println(getClass().getName()+".update:\n\t"+e);
e.printStackTrace();
}
}
}.start();
}else if(type.equals(ScannerIOMetadata.FILE)){ // acquired image as file (twain only for the time being)
final File file=metadata.getFile(); // make reference copy here to avoid race condition
new Thread(){
@Override
public void run(){
try{
open(file.getPath());
}catch(Exception e){
System.out.println("9\b"+getClass().getName()+".update:\n\t"+e);
System.err.println(getClass().getName()+".update:\n\t"+e);
e.printStackTrace();
}finally{
if(!file.delete()){
System.out.println("9\b"+getClass().getName()+".update:\n\tCould not delete: "+file.getPath());
System.err.println(getClass().getName()+".update:\n\tCould not delete: "+file.getPath());
}
}
}
}.start();
}else if(type.equals(ScannerIOMetadata.NEGOTIATE)){
negotiate(metadata);
}else if(type.equals(ScannerIOMetadata.STATECHANGE)){
System.out.println("Scanner State "+metadata.getStateStr());
if(metadata instanceof TwainIOMetadata){ // TWAIN only !
if(metadata.isState(TwainConstants.STATE_TRANSFERREADY)){ // state = 6
TwainSource source = ((TwainIOMetadata)metadata).getSource();
try{
TwainImageInfo imageInfo=new TwainImageInfo(source);
imageInfo.get();
System.out.println(imageInfo.toString());
}catch(Exception e){
System.out.println("3\b"+getClass().getName()+".update:\n\tCannot retrieve image information.\n\t"+e);
}
try{
TwainImageLayout imageLayout=new TwainImageLayout(source);
imageLayout.get();
System.out.println(imageLayout.toString());
}catch(Exception e){
System.out.println("3\b"+getClass().getName()+".update:\n\tCannot retrieve image layout.\n\t"+e);
}
}else if(metadata.isState(TwainConstants.STATE_TRANSFERRING)){ // state = 7
TwainSource source = ((TwainIOMetadata)metadata).getSource();
try{
int[] tweis=new int[0x1240-0x1200];
for(int i=0;i<tweis.length;i++){tweis[i]=0x1200+i;}
TwainExtImageInfo imageInfo=new TwainExtImageInfo(source,tweis);
imageInfo.get();
System.out.println(imageInfo.toString());
}catch(Exception e){
System.out.println("3\b"+getClass().getName()+".update:\n\tCannot retrieve extra image information.\n\t"+e);
}
}
}
}else if(type.equals(ScannerIOMetadata.INFO)){
System.out.println(metadata.getInfo());
}else if(type.equals(ScannerIOMetadata.EXCEPTION)){
System.out.println("9\b"+metadata.getException().getMessage());
metadata.getException().printStackTrace();
}
}
private void negotiate(ScannerIOMetadata metadata){
ScannerDevice sd=metadata.getDevice(); // SANE & TWAIN
try{
sd.setShowUserInterface(false);
System.out.println("9\b"+e.getMessage());
}
if(metadata instanceof TwainIOMetadata){ // TWAIN only!
TwainSource source=((TwainIOMetadata)metadata).getSource();
try{
TwainCapability[] caps=source.getCapabilities(); // print out all the capabilities
for(int i=0;i<caps.length;i++){
System.out.println(caps[i].toString());
}
}catch(Exception e){
System.out.println("9\b"+e.getMessage());
}
}
}
}