Answer the question
In order to leave comments, you need to log in
How can I make sure that my code saves the screen correctly?
Greetings viewers!
Actually, my screenshot is saved incorrectly - it is always saved under the name screenshot-0
The code is below
static long screenshotCount = 0;
public static void createScreenshot() throws IOException, HeadlessException, AWTException {
BufferedImage image = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
if(Files.exists(Paths.get(ConfigurationProvider.gameDirectory + "\\screenshots\\screenshot-" + screenshotCount + ".jpg"))) {
screenshotCount++;
return;
}else {
ImageIO.write(image, "jpg", new File(ConfigurationProvider.gameDirectory + "\\screenshots\\screenshot-" + screenshotCount + ".jpg"));
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question