Created
August 24, 2012 10:50
-
-
Save kimble/3449046 to your computer and use it in GitHub Desktop.
Java screenshot robot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Test; | |
import javax.imageio.ImageIO; | |
import java.awt.*; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import java.io.IOException; | |
import static java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment; | |
public class ScreenshotTest { | |
@Test | |
public void screenshottingRobotExperiment() throws AWTException, IOException { | |
GraphicsEnvironment ge = getLocalGraphicsEnvironment(); | |
for (GraphicsDevice screen : ge.getScreenDevices()) { | |
GraphicsConfiguration configuration = screen.getDefaultConfiguration(); | |
Rectangle bounds = configuration.getBounds(); | |
Rectangle screenRectangle = new Rectangle((int) bounds.getWidth(), (int) bounds.getHeight()); | |
Robot robot = new Robot(screen); | |
BufferedImage screenCapture = robot.createScreenCapture(screenRectangle); | |
ImageIO.write(screenCapture, "png", new File("c:/output/" + screen.getIDstring() + ".png")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment