How to Capture screenshot using java

import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class ScreenCapture {
	public static void main(String[] args) throws Exception{
		Robot robot = new Robot();
		Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
		BufferedImage screen = robot.createScreenCapture(rectangle);
		ImageIO.write(screen, "JPG", new File("C:\\Users\\sekharbabub\\Desktop\\Screen.jpg"));
	}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s