Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.rabrg.util;
- import java.awt.AWTException;
- import java.awt.Rectangle;
- import java.awt.Robot;
- import java.awt.Toolkit;
- import java.awt.image.BufferedImage;
- /**
- * A utility class which uses {@link Robot} to capture the user's screen image into a {@link BufferedImage}.
- * @author Ryan Greene
- *
- */
- public final class Capture {
- /**
- * The {@link Robot} instance.
- */
- private static Robot robot;
- /**
- * The screen's size represented as a {@link Rectangle}.
- */
- private static Rectangle screen;
- /**
- * Initiates the capture utility.
- * @throws AWTException If an exception is thrown.
- */
- public static void initiate() throws AWTException {
- robot = new Robot();
- screen = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
- }
- /**
- * Sets the delay between {@link Robot} events being registered and being executed.
- * @param delay The delay.
- */
- public static void setDelay(final int delay) {
- robot.setAutoDelay(delay);
- }
- /**
- * Captures the current screen's image, excluding the mouse cursor.
- * @return The captured screen image.
- */
- public static BufferedImage capture() {
- return robot.createScreenCapture(screen);
- }
- /**
- * Captures the current screen's image, excluding the mouse cursor.
- * @param screen The dimensions of the screen being captured.
- * @return The captured screen image.
- */
- public static BufferedImage capture(Rectangle screen) {
- return robot.createScreenCapture(screen);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement