|
Groovy Documentation | |||||||
| FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.wordpress.tipsforjava.swing.ScreenImage
public class ScreenImage extends Object
Convenience class to create and optionally save to a file a BufferedImage of an area on the screen. Generally there are four different scenarios. Create an image of: a) an entire component b) a region of the component c) the entire desktop d) a region of the desktop The first two use the Swing paint() method to draw the component image to the BufferedImage. The latter two use the AWT Robot to create the BufferedImage. The created image can then be saved to a file by usig the writeImage(...) method. The type of file must be supported by the ImageIO write method. Although this class was originally designed to create an image of a component on the screen it can be used to create an image of components not displayed on a GUI. Behind the scenes the component will be given a size and the component will be layed out. The default size will be the preferred size of the component although you can invoke the setSize() method on the component before invoking a createImage(...) method. The default functionality should work in most cases. However the only foolproof way to get a image to is make sure the component has been added to a realized window with code something like the following: JFrame frame = new JFrame(); frame.setContentPane( someComponent ); frame.pack(); ScreenImage.createImage( someComponent );
| Field Summary | |
|---|---|
private static List |
types
|
| Constructor Summary | |
ScreenImage()
|
|
| Method Summary | |
|---|---|
static BufferedImage
|
createDesktopImage()
Convenience method to create a BufferedImage of the desktop |
static BufferedImage
|
createImage(JComponent component)
|
static BufferedImage
|
createImage(JComponent component, Rectangle region)
|
static BufferedImage
|
createImage(Component component)
|
static BufferedImage
|
createImage(Rectangle region)
Create a BufferedImage from a rectangular region on the screen. |
static void
|
layoutComponent(Component component)
|
static void
|
writeImage(BufferedImage image, String fileName)
Write a BufferedImage to a File. |
| Methods inherited from class Object | |
|---|---|
| wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
| Field Detail |
|---|
private static List types
| Constructor Detail |
|---|
ScreenImage()
| Method Detail |
|---|
public static BufferedImage createDesktopImage()
fileName - name of file to be created or null
public static BufferedImage createImage(JComponent component)
public static BufferedImage createImage(JComponent component, Rectangle region)
public static BufferedImage createImage(Component component)
public static BufferedImage createImage(Rectangle region)
region - region on the screen to create image from
static void layoutComponent(Component component)
public static void writeImage(BufferedImage image, String fileName)
image - image to be writtenfileName - name of file to be created
Groovy Documentation