Java Robot .createScreenCapture (Rectangle screenRect)

Syntax

Robot.createScreenCapture(Rectangle screenRect) has the following syntax.

public BufferedImage createScreenCapture(Rectangle screenRect)

Example

In the following code shows how to use Robot.createScreenCapture(Rectangle screenRect) method.


import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
//w w  w.ja va2  s  .  co  m
public class Main {
  public static void main(String[] argv) throws Exception {
    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);

  }
}




















Home »
  Java Tutorial »
    java.awt »




BasicStroke
BorderLayout
CardLayout
Color
Cursor
Desktop
DesktopManager
DisplayMode
EventQueue
FlowLayout
FocusTraversalPolicy
Font
FontMetrics
GradientPaint
Graphics
Graphics2D
GraphicsConfiguration
GraphicsDevice
GraphicsEnvironment
GridBagConstraints
GridBagLayout
GridLayout
Image
ItemSelectable
KeyboardFocusManager
LayoutManager
LayoutManager2
Point
Rectangle
Robot
Shape
SplashScreen
SystemColor
SystemTray
TexturePaint
TrayIcon
Toolkit
Transparency