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

时间:2012-12-06 10:59:47

标签: java jquery html5 web applet

我需要问一下是否有办法(小程序或任何其他想法)在网页上的div上截取内容的截图???

我发现这个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;
    }
}

感谢

1 个答案:

答案 0 :(得分:0)

这类似于以下问题:Take a screenshot of a web page in Java