Given an instance of java.awt.Graphics, is it possible to get the surface that it is rendering on? I'm trying to capture the current display of a component, but because the actual painting isn't handled in it's paint method, i'm unable to directly paint on a new surface. I was hoping that by getting the surface that the Graphics instance is rendering on, somehow I'd be able to capture the input. If I'm looking in the wrong direction, please let me know.
Asked
Active
Viewed 157 times
1 Answers
0
Actually paint/paintComponent should do. Of a BufferedImage one can get its Grapics and use the component to paint in that. (And later dispose the graphics!)
This is assuming you are using swing.
Otherwise the java.awt.Robot class lets one do things like screen shots
Robot robot = new Robot();
Rectangle area = ...
BufferedImage bufferedImage = robot.createScreenCapture(area);

Joop Eggen
- 107,315
- 7
- 83
- 138
-
Thanks for your response, the problem actually lies in the fact that the code that handles painting isn't in the paint method, instead the paint method triggers a flag that allows the component to paint to a surface that's stored in the component at initialization (Which is out of my control). You're right in the fact that I could use the robot class to capture it, but the problem with that lies in the fact that it could try to capture the display when the program is minimized (or when it's overlayed by another window), and in that case it wouldn't work. – Christopher Carpenter Dec 10 '13 at 18:49
-
On an invalidate/repaint/paintImmediately maybe, but I understand that might be hard, if the repainting is not programmed properly. Good luck. – Joop Eggen Dec 10 '13 at 20:35