Skip to content

Instantly share code, notes, and snippets.

@eddturtle
Created October 15, 2012 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddturtle/3895739 to your computer and use it in GitHub Desktop.
Save eddturtle/3895739 to your computer and use it in GitHub Desktop.
Take a Screenshot with Java
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"));
}
}
@LEVELONCODER
Copy link

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment