Screen Capture
For documentation purposes (and perhaps remote support), we need
snapshot images of our application.
So let's build such support directly into our application itself.
href="https://aptframework.dev.java.net/gooey/screenCapture.html">
align="left" hspace="8"/>
A part of "Gooey Beans, the GUI part of a trilogy in 42 parts"
Code Snippets
We can capture whole desktop, and save it to a PNG file, as follows.
public void captureScreen(String fileName) throws Exception {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
BufferedImage image = new Robot().createScreenCapture(new Rectangle(screenSize));
ImageIO.write(image, "png", new File(fileName));
}
Alternatively, we might capture our JFrame, including its window decoration, as follows.
public void captureFrame(JFrame frame, String fileName) throws Exception {
BufferedImage image = new Robot().createScreenCapture(frame.getBounds());
ImageIO.write(image, "png", new File(fileName));
}
- Login or register to post comments
- Printer-friendly version
- evanx's blog
- 1016 reads





