So, Friday came? I think? Maybe? Yeah, the jury is still out on that one. I for one enjoy when a weekend comes. It’s quite a nice detour through which everything is possible. No, I’m not sure if I understand what I just wrote either. But hey, it’s the weekend. There’s nothing to do but go and do whatever there is to do! The world is our oyster as it were. Nope, don’t have a clue where that phrase came from either. It would be nice to be able to determine something in this life. I think? Maybe? Who knows. As long as I’m livin’ I ain’t dyin’. I guess that’s one way to look at it all with a perspective that matches nothing. Been thinking lately, life isn’t as bad as I thought it was. I mean is. Yeah you know what I mean. It’s life after all. There’s nothing to worry about when life comes your way. You either buckle down and face the music, or you wimp out and let life do its thing. The choice is yours.
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