我将使用我的应用程序扫描文档,该应用程序使用 JTwain 库进行该过程。但现在它给出了这个错误。是否有任何其他要求 1. 添加 dll 文件 2. 添加运行路径 3. 在我的运行配置窗口中添加参数变量。?
Exception in thread "Thread-8" java.lang.UnsatisfiedLinkError: no AspriseJTwain in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.asprise.util.jtwain.SourceManager.init(SourceManager.java:222)
at com.asprise.util.jtwain.SourceManager.<init>(SourceManager.java:36)
at com.asprise.util.jtwain.SourceManager.instance(SourceManager.java:28)
at com.bellvantage.docscanner.util.DocScaner.scanDoc(DocScaner.java:58)
at com.bellvantage.docscanner.util.DocScaner.run(DocScaner.java:49)
请帮我解决这个问题。谢谢
这里显示了我的代码
import com.bellvantage.docscanner.domain.ScannedDoc;
import com.asprise.util.jtwain.JTwainException;
import com.asprise.util.jtwain.Source;
import com.asprise.util.jtwain.SourceManager;
import com.bellvantage.docscanner.Infrastructure.ScannedDocDAO;
import com.bellvantage.docscanner.domain.DocScanUser;
import com.bellvantage.docscanner.domain.DocumentGroup;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.logging.Level;
import javax.imageio.ImageIO;
import org.apache.log4j.Logger;
/**
*
* @author JinathN
* @Created On Dec 11, 2009
*/
public class DocScaner extends Thread {
Source scanerSource;
private DocScanListener docScanListener;
private DocumentGroup dg;
DocScanUser user;
ScannedDocDAO scannedDocDAO;
public Logger logger= Logger.getLogger(DocScaner.class);
public DocScaner(DocumentGroup dg, DocScanUser user) {
this.dg = dg;
this.user = user;
scannedDocDAO = new ScannedDocDAO();
}
@Override
public void run() {
scanDoc();
}
private void scanDoc() {
try {
BufferedImage image;
BufferedImage imgPrev;
synchronized (SourceManager.class) {
//scanerSource = SourceManager.instance().selectSourceUI();
scanerSource = SourceManager.instance().getDefaultSource();
if (scanerSource != null) {
scanerSource.setUIEnabled(false);
scanerSource.setAutoFeed(true);
scanerSource.setFeederEnabled(true);
scanerSource.setClearBuffers(MAX_PRIORITY);
scanerSource.setClearPage(true);
if (scanerSource != null) {
docScanListener.scaningStarted();
ScannedDoc scannedDoc;
do {
System.out.println("After While loop");
try {
image = scanerSource.acquireImageAsBufferedImage();
//scanerSource.acquireImage();
if (image != null) {
imgPrev = getImgPreview(image);
scannedDoc = saveDoc(image, dg, user);
docScanListener.previewFound(imgPrev, scannedDoc.getId());
scannedDoc = null;
System.out.println("Assigned Doc to null");
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
continue;
}
} while (scanerSource.hasMoreImages());
}
scanerSource.close();
docScanListener.scaningFinished();
System.out.println("Final step");
}
SourceManager.closeSourceManager();
System.out.println("Source closed");
}
} catch (JTwainException ex) {
ex.printStackTrace();
}
}
private ScannedDoc saveDoc(BufferedImage image, DocumentGroup dg, DocScanUser user) {
ScannedDoc doc = new ScannedDoc();
doc.setDoc(getByteArray(image));
doc.setDocumentGroup(this.dg);
doc.setScanedUser(this.user);
doc.setStatus("PENDING");
doc.setScanedTime(new Timestamp(System.currentTimeMillis()));
doc.setBranch(ScanerSession.getBo()== null ? "": ScanerSession.getBo().getBranchName());
scannedDocDAO.insert(doc);
doc.setDoc(null);
return doc;
}
private BufferedImage getImgPreview(BufferedImage sourceImage) {
BufferedImage biPreview = null;
double previewRatio = 80.0d / 450.0d;
System.out.println("Ratio=" + previewRatio);
System.out.println("w=" + sourceImage.getWidth());
System.out.println("h=" + sourceImage.getHeight());
int w = (int) (sourceImage.getWidth() * previewRatio);
int h = (int) (sourceImage.getHeight() * previewRatio);
System.out.println("w=" + w + " h=" + h);
biPreview = getCompatibleImage(w, h);
Graphics2D graphics2D = biPreview.createGraphics();
double xScale = (double) w / sourceImage.getWidth();
double yScale = (double) h / sourceImage.getHeight();
AffineTransform at = AffineTransform.getScaleInstance(xScale, yScale);
graphics2D.drawRenderedImage(sourceImage, at);
graphics2D.dispose();
return biPreview;
}
private BufferedImage getCompatibleImage(int w, int h) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
BufferedImage image = gc.createCompatibleImage(w, h);
return image;
}
public void setPreviewListener(DocScanListener previewListener) {
this.docScanListener = previewListener;
}
/*private byte[] getByteArray1(BufferedImage image) {
byte[] img=null;
try {
ByteArrayOutputStream os = new ByteArrayOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
encoder.encode(image);
img=os.toByteArray();
} catch (IOException ex) {
} catch (ImageFormatException ex) {
}
return img;
}*/
private byte[] getByteArray(BufferedImage image) {
ByteArrayOutputStream os = null;
byte[] content = null;
try {
os = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", os);
content = os.toByteArray();
} catch (IOException ex) {
} finally {
try {
os.close();
image = null;
} catch (IOException ex) {
logger.error("getByteArray " + ex);
}
}
return content;
}
public void deleteDocument(Long id) {
ScannedDoc delDoc = new ScannedDoc();
delDoc.setId(id);
new ScannedDocDAO().delete(delDoc);
}
public void setDg(DocumentGroup dg) {
this.dg = dg;
}
}