Java Web screenshot
The Code is as follows:
Package com. util; import java. awt. AWTException; import java. awt. desktop; import java. awt. dimension; import java. awt. graphics; import java. awt. image; import java. awt. rectangle; import java. awt. robot; import java. awt. toolkit; import java. awt. event. keyEvent; import java. awt. image. bufferedImage; import java. io. file; import java. io. IOException; import java.net. URISyntaxException; import java.net. URL; import javax. imageio. imageIO; public class CutPicture {public static void main (String [] args) throws Exception, IOException, URISyntaxException, AWTException {// This method is only applicable to JdK1.6 and later Desktop versions. getDesktop (). browse (new URL ("http://java.662p.com /"). toURI (); Robot robot = new Robot (); robot. delay( 10000); Dimension d = new Dimension (Toolkit. getdefatooltoolkit (). getScreenSize (); int width = (int) d. getWidth (); int height = (int) d. getHeight (); // maximize the browser's 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); // Save the image ImageIO. write (bi, "jpg", new File ("c:/open.jpg "));}}
Note: For more information, see java tutorial network.