美文网首页
截图工具 java

截图工具 java

作者: Trouble_Ma | 来源:发表于2019-03-20 19:00 被阅读0次
    /**
         * 方法详解:该方法利用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

          本文链接:https://www.haomeiwen.com/subject/mkgtvqtx.html