Sometimes you just need to capture a screenshot in Java. Well look no further here's the code in question!
import java.awt.AWTException;import java.awt.HeadlessException;import java.awt.Rectangle;import java.awt.Robot;import java.awt.Toolkit;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;public class ScreenShot { public static void main(String[] args) throws IOException { BufferedImage image; try { image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())); ImageIO.write(image, "png", new File("screenshot.png")); } catch (HeadlessException e) { e.printStackTrace(); } catch (AWTException e) { e.printStackTrace(); } }}
No comments:
Post a Comment