There needs to be more sleep hours in the day. I could have used a bit more sleep this morning let’s face it. But that’s not going to happen now. Oh great I have hiccups now. I don’t know where that came from. Let’s see if I can hold my breath. If that helps then the hiccups will be gone and everything will be fine and dandy. Nope that’s not happening either. Dang it. Maybe I’ll get there maybe.
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();
}
}
}
Comments
Post a Comment