views:

2246

answers:

2

Simple as the title states: Can you use only Java commands to take a screenshot and save it? Or, do I need to use an OS specific program to take the screenshot and then grab it off the clipboard?

+3  A: 

http://schmidt.devlib.org/java/save-screenshot.html

John Millikin
The reason I didn't accept your answer was because it was someone elses code.
jjnguy
+18  A: 

Believe it or not, you can actually use java.awt.Robot to "create an image containing pixels read from the screen." You can then write that image to a file on disk.

I just tried it, and the whole thing ends up like:

Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture = new Robot().createScreenCapture(screenRect);
ImageIO.write(capture, "bmp", new File(args[0]));

NOTE: This will only capture the primary monitor. See GraphicsConfiguration for multi-monitor support.

David Citron
Wow - who would have thought. That is very very cool.
Michael Neale
I'd never come across java.awt.Robot. That's one impressive and useful class.
Free Wildebeest
I wonder if this is what screen sharing applications like Elluminate (http://www.elluminate.com/) use.
Flash84x