Java Screen Capture captureScreen()

Here you can find the source of captureScreen()

Description

capture Screen

License

Apache License

Declaration

public static BufferedImage captureScreen() throws Exception 

Method Source Code


//package com.java2s;
/*//from w w w.  j  a va 2  s. c o  m
 * Copyright 2012 Timothy Lin <lzh9102@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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() throws Exception {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle screenRectangle = new Rectangle(screenSize);
        Robot robot = new Robot();
        BufferedImage image = robot.createScreenCapture(screenRectangle);
        return image;
    }
}

Related

  1. captureScreen(final Rectangle screenRect)
  2. captureScreen(Rectangle rect)
  3. captureScreen(String filename)
  4. screenshot(Rectangle dims, Robot r)