简体   繁体   English

Applet Java截取我网页的一部分的屏幕截图

[英]Applet Java To take a screenshot of a part of my web page

i need to ask if there are a way ( applet or any think else ) to take a screenshot of the content on a div in webpage ??? 我需要问是否有办法(小程序或其他想法)对网页上div的内容进行截图?

i found this java code to take screenshot of the full screen : 我发现此Java代码拍摄了全屏截图:

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ScreenShot
{
    /**
    method to capture screen shot
    @param String uploadPath to save screen shot as image
    @returns boolean true if capture successful else false
    */
    boolean captureScreenShot(String uploadPath)
    {
        boolean isSuccesful = false;
        Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
        BufferedImage capture;
        try
        {
            capture = new Robot().createScreenCapture(screenRect);
            // screen shot image will be save at given path with name "screen.jpeg"
            ImageIO.write(capture, "jpg", new File( uploadPath, "screen.jpeg"));
            isSuccesful = true;
        }
        catch (AWTException awte)
        {
            awte.printStackTrace();
            isSuccesful = false;
        }
        catch (IOException ioe)
        {
            ioe.printStackTrace();
            isSuccesful = false;
        }
        return isSuccesful;
    }
}

thanks 谢谢

这类似于以下问题: 用Java截取网页的屏幕截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM