开发者

reading file through scanner device in java

开发者 https://www.devze.com 2023-01-01 10:58 出处:网络
how 开发者_如何转开发can i read file of any type using scanner hardware device in java Have a look at JTwain: http://asprise.com/product/jtwain/faq.php

how 开发者_如何转开发can i read file of any type using scanner hardware device in java


Have a look at 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();
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消