Java Utililty Methods Screen Capture

List of utility methods to do Screen Capture

Description

The list of methods to do Screen Capture are organized into topic(s).

Method

BufferedImagecaptureScreen()
capture Screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRectangle);
return image;
BufferedImagecaptureScreen(final Rectangle screenRect)
capture Screen
if (robot == null) {
    throw new AWTException("the platform configuration does not allow low-level input control");
return robot.createScreenCapture(screenRect);
BufferedImagecaptureScreen(Rectangle rect)
capture Screen
try {
    return (new Robot()).createScreenCapture(rect);
} catch (AWTException e) {
return null;
voidcaptureScreen(String filename)
Captures the screen.
BufferedImage image = new Robot()
        .createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(image, "png", new File(filename));
BufferedImagescreenshot(Rectangle dims, Robot r)
screenshot
BufferedImage screenshot = r.createScreenCapture(dims);
return screenshot;
byte[]screenShot(String format)
Stores a screenshot to the bynary array.
try {
    Robot robot = new Robot();
    Rectangle captureSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    BufferedImage bufferedImage = robot.createScreenCapture(captureSize);
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    ImageIO.write(bufferedImage, format, bo);
    return bo.toByteArray();
} catch (AWTException e) {
...
byte[]takeScreenShot(boolean showCursor)
This function handle the sreenshot
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedImage img = null;
byte[] out = null;
try {
    img = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
    if (showCursor) {
        Image cursor = ImageIO.read(new File("res/ratty/img/cursor.gif"));
        int x = MouseInfo.getPointerInfo().getLocation().x;
...
voidtakeScreenshot(String fileName, String formatName)
take Screenshot
Rectangle screenBounds = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage image = new Robot().createScreenCapture(screenBounds);
ImageIO.write(image, formatName, new File(fileName));