截圖工具 java

/**
     * 方法詳解:該方法利用Robat提供的強(qiáng)大桌面操作能力
     *          硬性調(diào)用瀏覽器打開(kāi)指定網(wǎng)頁(yè),并將網(wǎng)頁(yè)信息保存到本地。
     * 優(yōu)勢(shì):簡(jiǎn)單易用,不需要任何第三方插件。
     * 缺點(diǎn):不能同時(shí)處理大量數(shù)據(jù),技術(shù)含量過(guò)低,屬于應(yīng)急型技巧。
     * @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();
        }

    }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容