我如何从打印机“扫描仪"中获取图像? [英] How i can get image from printer "Scanner"

查看:92
本文介绍了我如何从打印机“扫描仪"中获取图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Java代码从打印机扫描仪"中获取图像,获取图像后,我要将其保存在项目文件夹中,我该怎么做?

I want to get image from printer "Scanner" by using java code , and after get image i want to save it on project folder , How i can do that ?

 public static void main(String args[]) {
    }

推荐答案

尝试一下,

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

参考文献: http://asprise.com/product/jtwain/faq.php

这篇关于我如何从打印机“扫描仪"中获取图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆