Java Screen Shot Code

From Simson Garfinkel
Jump to navigationJump to search

Make a Screen Shot with Java

import java.awt.image.*;
import java.awt.*;
import javax.swing.*;
import javax.imageio.*;

public class ScreenShot
    public static void main(String[] args)
		// Get the screen size
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Rectangle rectangle = new Rectangle(0, 0, screenSize.width, screenSize.height);
		Robot robot = new Robot();
		BufferedImage image = robot.createScreenCapture(rectangle);
		File file;

		// Save the screenshot as a png
		file = new File("screen.png");
		ImageIO.write(image, "png", file);

	    } catch (Exception e) {