I am currently making a fullscreen game and I want to be able to take some screenshots.
I have found this little code snippet:
BufferedImage image =
new Robot().createScreenCapture(new Rectangle(w.getX(), w.getY(),w.getWidth(),w.getHeight()));
ImageIO.write(image, "jpg", new File("C:\\Users\\Kaizer\\Desktop\\", "ScreenShot" + counter + ".jpg"));
I know it doesnt look pretty, but it makes a screenshot, but from my desktop, and not my actual fullscreen game. The Windows screenshots does the same.
I know there is something I overlooked, but I can’t figure it out for the life of me.
By the way: this code is run when the player presses the F11 button. It is not its own method.
If you wrote your game with Swing or AWT, instead of using
Robot, you can do the following:Note: Depending on the
Componentyou’re using, it may or may not need to be visible. But seeing as you’re taking a picture from a game, I’m pretty sure that won’t matter.