简体   繁体   English

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

[英]reading file through scanner device in java

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

Have a look at JTwain: http://asprise.com/product/jtwain/faq.php 看看JTwain: http ://asprise.com/product/jtwain/faq.php

They provide the following example code snippet: 他们提供了以下示例代码片段:

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();
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM