截图工具 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();
        }

    }

你可能感兴趣的:(截图工具 java)