Create a Screenshot taker Program in Java

We could easily take a screenshot of the entire screen, by pressing the Print Screen button on your keyboard. But what if you want to take screen shot programmatically? So today we will see a program on how we can take screenshots in java and save it as an image file

So this example uses Java.awt.Robot class to capture the screen pixels and returns a BufferedImage.we can play with mouse and keyboard controls using Java.awt.Robot class.


The below java program demonstrates How To Take Screen Shots In Java
and Save it as an Image File


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"));
}
}


Share on Google Plus

0 replies:

Post a Comment