23 package com.realtime.crossfire.jxclient.commands;
28 import java.awt.Color;
29 import java.awt.Graphics;
30 import java.awt.image.BufferedImage;
31 import java.io.IOException;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
34 import javax.imageio.ImageIO;
35 import org.jetbrains.annotations.NotNull;
75 public void execute(@NotNull
final String args) {
80 }
catch (
final IOException ex) {
81 drawInfoError(
"Failed to create screenshot filename: "+ex.getMessage());
85 file = Paths.get(args);
89 final Graphics g = image.createGraphics();
91 g.setColor(Color.black);
98 ImageIO.write(image,
"png", file.toFile());
99 }
catch (
final IOException ex) {
100 drawInfoError(
"Cannot write screenshot "+file+
": "+ex.getMessage());
102 }
catch (
final NullPointerException ignored) {
107 drawInfo(
"Saved screenshot to "+file);
114 final StringBuilder sb =
new StringBuilder();
115 sb.append(
"Creates a screenshot image\n");
117 sb.append(
"Usage: screenshot\n");
118 sb.append(
"Usage: screenshot <file>\n");
120 sb.append(
"Write the current display contents into a PNG file. ");
121 sb.append(
"If <file> is omitted, the file names 'screenshot0.png', ..., 'screenshot9.png' are used instead.\n");
122 sb.append(
"Note: If the file already exists, it is overwritten without confirmation.\n");
123 return sb.toString();