Created
October 15, 2012 21:41
-
-
Save eddturtle/3895739 to your computer and use it in GitHub Desktop.
Take a Screenshot with Java
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 java.awt.Rectangle; | |
import java.awt.Robot; | |
import java.awt.Toolkit; | |
import java.awt.image.BufferedImage; | |
import java.awt.Desktop; | |
import java.io.File; | |
import javax.imageio.ImageIO; | |
public class Main { | |
public static void main(String[] args) throws Exception | |
{ | |
Robot r = new Robot(); | |
BufferedImage screenShot = r.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); | |
ImageIO.write(screenShot, "JPG", new File("screenshot.jpg")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice!