Return to Snippet

Revision: 36142
at November 18, 2010 19:51 by visudex


Initial Code
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;

class ScreenCapture {
  public static void main(String args[]) throws AWTException, IOException {
     // Captures the image from the screen
     BufferedImage screencapture = new Robot().createScreenCapture(
           new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); //Gets the size of the screen

     // Writes the File as a PNG
     File file = new File("screencapture.png");//Saves your file in the project folder
     ImageIO.write(screencapture, "png", file);
  }
}

Initial URL

                                

Initial Description
This snippet will allow you to capture your screen in Java and saves the image as a PNG

Initial Title
Screen Shot in Java and saves as PNG

Initial Tags
image, java

Initial Language
Java