我正在开发一个使用Fujitsu 7260扫描文件的java应用程序,但我遇到的问题是当我按下扫描按钮时扫描用户界面挂起
我的代码如下:
try {
Scanner scanner=null;
scanner = Scanner.getDevice();
devices=scanner.getDeviceNames();
scanner.select(devices[1]);
scanner.addListener((ScannerListener) this);
} catch (Exception e) {
}
扫描按钮操作:
try
{
scanner.acquire();
}
catch(Exception ex){
ex.getMessage();
}
处理扫描事件的方法:
public void update(ScannerIOMetadata.Type type, ScannerIOMetadata metadata) {
startScan.setEnabled(true);
if (type.equals(ScannerIOMetadata.ACQUIRED)) {
BufferedImage SCimg = metadata.getImage();
//ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
//op.filter(img, img);
Image scaledInstance = SCimg.getScaledInstance(jLabel1.getWidth(), jLabel1.getHeight(), Image.SCALE_DEFAULT);
ImageIcon icon = new ImageIcon(scaledInstance);
jLabel1.setIcon(icon);
scannedImagesList.add(SCimg);
pages.setText(scannedImagesList.size()+"");
currentPage.setText(scannedImagesList.size()+"");
if(!saveScanned.isEnabled())
saveScanned.setEnabled(true);
if(Integer.parseInt(pages.getText()) == Integer.parseInt(currentPage.getText()))
{
next.setEnabled(false);
if(Integer.parseInt(pages.getText())==1)
{
next.setEnabled(false);
prev.setEnabled(false);
}
else
if(Integer.parseInt(pages.getText())> 1)
{
prev.setEnabled(true);
}
}
startScan.setEnabled(true);
try {
new uk.co.mmscomputing.concurrent.Semaphore(0, true).tryAcquire(2000, null);
} catch (InterruptedException e) {
IJ.error(e.getMessage());
// e.printStackTrace();
}
} else if (type.equals(ScannerIOMetadata.NEGOTIATE)) {
ScannerDevice device = metadata.getDevice();
try {
device.setResolution(100);
device.setShowUserInterface(false);
device.setShowProgressBar(true);
} catch (ScannerIOException e) {
IJ.error(e.getMessage());
}
try{
}
catch(Exception ex){}
/*
* More options if necessary!
* device.setShowProgressBar(true);
* device.setRegionOfInterest(0,0,210.0,300.0);z
* device.setResolution(
100); }catch(Exception e){
* e.printStackTrace(); }
*/
} else if (type.equals(ScannerIOMetadata.STATECHANGE)) {
// IJ.error(metadata.getStateStr());
} else if (type.equals(ScannerIOMetadata.EXCEPTION)) {
IJ.error(metadata.getException().toString());
}
}
正在使用名为mmscomputing
究竟是什么问题?有没有可以帮助我的开源库?
提前致谢