通过java中的扫描仪设备读取文件

时间:2010-05-25 12:49:15

标签: java

如何使用java中的扫描仪硬件设备读取任何类型的文件

1 个答案:

答案 0 :(得分:1)

看看JTwain:http://asprise.com/product/jtwain/faq.php

他们提供以下示例代码段:

try {

    Source source = SourceManager.instance().getDefaultSource(); // Acquire image from default source
    source.open();

    Image image = source.acquireImage(); // Acquire the image

    // Loads the image completely ...
    // Click here to find how to load images completely with MediaTracker.
    // ...

    int imageWidth = image.getWidth(this);
    int imageHeight = image.getHeight(this);

    BufferedImage bufferedImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);

    Graphics2D g2 = bufferedImage.createGraphics();
    g2.drawImage(image, 0, 0, this);

    // Now, you can use the bufferedImage object ...

}catch(Exception e) {
    e.printStackTrace();
}finally{
    SourceManager.closeSourceManager();
}