capture Screen - Java 2D Graphics

Java examples for 2D Graphics:Image

Description

capture Screen

Demo Code


//package com.java2s;
import java.awt.Dimension;

import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage captureScreen() {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screenSize = toolkit.getScreenSize();
        Rectangle screenRect = new Rectangle(screenSize);
        Robot robot;/*from  w  w w. ja v a  2 s  .c  om*/
        try {
            robot = new Robot();
            Thread.sleep(2000);
            return robot.createScreenCapture(screenRect);
        } catch (Exception e) {
            return null;
        }
    }
}

Related Tutorials