this is a nice proof of concept of how to make a screenshot in java, llok at the code
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment; import java.awt.Rectangle; import java.awt.Robot; import java.awt.image.BufferedImage; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGEncodeParam; import com.sun.image.codec.jpeg.JPEGImageEncoder; public class ScreenCapture { public static void main(String[] args) throws FileNotFoundException, IOException, AWTException { GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); for (int j = 0; j < gs.length; j++) { GraphicsDevice gd = gs[j]; Robot r = new Robot(); Rectangle rect = gd.getConfigurations()[0].getBounds(); BufferedImage image = r.createScreenCapture(rect); generateJPG(image, “screen” + j + “.jpg”); } } private static void generateJPG(BufferedImage buffer, String fileName) throws FileNotFoundException, IOException { FileOutputStream file = new FileOutputStream(fileName); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(file); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(buffer); param.setQuality(0.75F, true); encoder.setJPEGEncodeParam(param); encoder.encode(buffer); file.close(); } } |