Take Screen Shot Using Java

In this article we will see how to take screen shot using Java. We will use Java AWT for this using Robot class.
Many times we use Print Screen and then pasting in Microsoft Paint to save it as image. The same thing we will do using Java.

So let's get started. Below is the complete code for that.

package com.example.awt;

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 ScreenShotTaker {

 public static void main(String[] args) {
  try {
   Robot robot = new Robot();
   Rectangle rect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
   
   BufferedImage screesnShot = robot.createScreenCapture(rect);
   
   ImageIO.write(screesnShot, "JPG", 
     new File ("YOUR_PATH\\screenshot.jpg"));
  } catch (Exception e) {
   e.printStackTrace();
  }
 }

}


0 Comments