截图工具 java

/**
     * 方法详解:该方法利用Robat提供的强大桌面操作能力
     *          硬性调用浏览器打开指定网页,并将网页信息保存到本地。
     * 优势:简单易用,不需要任何第三方插件。
     * 缺点:不能同时处理大量数据,技术含量过低,属于应急型技巧。
     * @throws URISyntaxException
     * @throws IOException
     * @throws MalformedURLException
     * @throws AWTException
     *
     */
    public void test3(){
        try {
            //此方法仅适用于JdK1.6及以上版本
            Desktop.getDesktop().browse(
                    new URL("http://www.baidu.com").toURI());
            Robot robot = new Robot();
            robot.delay(10000);
            Dimension d = new Dimension(Toolkit.getDefaultToolkit().getScreenSize());
            int width = (int) d.getWidth();
            int height = (int) d.getHeight();
            //最大化浏览器
            robot.keyRelease(KeyEvent.VK_F11);
            robot.delay(2000);
            Image image = robot.createScreenCapture(new Rectangle(0, 0, width,
                    height));
            BufferedImage bi = new BufferedImage(width, height,
                    BufferedImage.TYPE_INT_RGB);
            Graphics g = bi.createGraphics();
            g.drawImage(image, 0, 0, width, height, null);
            //保存图片
            ImageIO.write(bi, "jpg", new File("d:/111.jpg"));
        }catch (Exception e){
            e.printStackTrace();
        }

    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容