Java Program To Take Screenshot

Java.awt.Robot class to capture the screen pixels and uses Imageio to save it as PNG image format. Just copy and paste the program in Notepad, save it and run the program to take screen shot.

Note:  The Screen shot image will be stored at the location where your program is stored.

import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.*;

class Snap
{
       public static void main(String args[]) 
      throws Exception
      {
                Robot awt_robot = new Robot();
               BufferedImage Entire_Screen=awt_robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize() ));
              ImageIO.write(Entire_Screen, "PNG", new File("Entire_Screen.png"));
      }
}







No comments: