Capturing a Screen Shot - Java 2D Graphics

Java examples for 2D Graphics:Screen

Description

Capturing a Screen Shot

Demo Code

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;

public class Main {
  public static void main(String[] args) {
    try {//from  w ww .  ja v a2 s . co  m
      Robot robot = new Robot();

      int x = 100;
      int y = 100;
      int width = 200;
      int height = 200;
      Rectangle area = new Rectangle(x, y, width, height);
      BufferedImage bufferedImage = robot.createScreenCapture(area);

      // Capture the whole screen
      area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
      bufferedImage = robot.createScreenCapture(area);
    } catch (AWTException e) {
    }
  }
}

Related Tutorials