Created
May 30, 2009 04:05
-
-
Save nandub/120362 to your computer and use it in GitHub Desktop.
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
//http://viralpatel.net/blogs/2009/01/how-to-take-screen-shots-in-java-taking-screenshots-java.html | |
import java.awt.Dimension; | |
import java.awt.Rectangle; | |
import java.awt.Robot; | |
import java.awt.Toolkit; | |
import java.awt.image.BufferedImage; | |
import javax.imageio.ImageIO; | |
import java.io.File; | |
... | |
public void captureScreen(String fileName) throws Exception { | |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); | |
Rectangle screenRectangle = new Rectangle(screenSize); | |
Robot robot = new Robot(); | |
BufferedImage image = robot.createScreenCapture(screenRectangle); | |
ImageIO.write(image, "png", new File(fileName)); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment