How can I capture the image of an AWT GUI?

Scott Stanchfield

You can use the printAll() method of Component to accomplish this.

As an example


Component comp = ... ; // the top-level component
                       // you want to capture

// create an image for the capture
Image img  = comp.createImage(comp.getWidth(), comp.getHeight());

// grab a graphics context for that image
Graphics g = img.getGraphics();

// print the GUI into that image
comp.printAll(g);

The resulting Image contains a picture of the GUI. Note that if the GUI is not displayes, you either need to display it first or call addNotify() on it to create the necessary peer components.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact