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?
views:
2246answers:
2The reason I didn't accept your answer was because it was someone elses code.
jjnguy
2008-09-12 17:59:56
+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
2008-09-12 04:56:20
I'd never come across java.awt.Robot. That's one impressive and useful class.
Free Wildebeest
2008-09-14 23:59:06
I wonder if this is what screen sharing applications like Elluminate (http://www.elluminate.com/) use.
Flash84x
2010-04-22 22:25:36