Screenshot in Java Using javax.imageio
Posted: November 17th, 2004 | No Comments »Perfect piece of Java code to take screenshots during experiments on CatchBob! From Take a screenshot and save it to a PNG file using javax.imageio.
// determine current screen size
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle screenRect = new Rectangle(screenSize);
// create screen shot
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRect);
// save captured image to PNG file
ImageIO.write(image, “png”, new File(outFileName));