Click to See Complete Forum and Search --> : Help


Moor
August 10th, 1999, 11:07 PM
Hi,

How to capture the screen from a Java application?
Thanx in advance.

Moor
moor73@yahoo.com

unicman
August 10th, 1999, 11:51 PM
I don't think there is direct way u can capture screen using Java.

It might be possible using Java Native Interface.

- UnicMan
http://members.tripod.com/unicman

RastaClown
August 11th, 1999, 12:42 PM
There is a way to "print" the screen. This may help. I have only done it with a Frame, and i'm not sure if it will work with an Applet but it may give you an idea. Create a graphics object that you can use. You can do this by obtaining it from the paint() method or:
Image image = createImage(width, height); // you'll need to decide the appropriate dimensions
Graphics g = image.getGraphics();


This will get you a graphics object you can use. If you're doing this in a Frame, you have to put the above code after the setVisible(true); line, otherwise the graphics will be null. Then you can paint anything you want on to this graphics object. In your case, you want to paint the application. So you need something that extends the Component class, like a Frame or something. All you need to do, is take the object(lets say a Frame in this case) and call the printAll() method and pass the Graphics object you created:
Component c = this; // Make a component object out of the Frame
c.printAll(g);



This will print the Parent component and all of its subcomponents. Now that you have the Graphics object with your app on it, you can do what you will with it. This is similar to what i used for an app to be able to print a screen shot of it. If you need to make a .gif or .jpeg, that's another issue, and you'll have to find out how to turn the object into a file of that type for extenal viewing.
Hope this helps.