CONTENTS | PREV | NEXT | Java 2D API |
The simplest way to create an image that you can use as an offscreen buffer is to use the Component.createImage method. This method creates an off-screen, drawable image that has the dimensions you specify. The created image is opaque and has the foreground and background colors of the Component. You cannot adjust the transparency of the image.By creating an image whose color space, depth, and pixel layout exactly match the window into which you are drawing, the image can be efficiently blitted to a graphics device. This allows drawImage to do its job quickly.
You can also construct a BufferedImage object directly to use as an offscreen buffer. This is useful when you need control over the offscreen image's type or transparency.
BufferedImage supports several predefined image types:
GraphicsConfiguration provides convenience methods that automatically create buffered images in the right format. You can also query the graphics configuration associated with the graphics device on which the window resides to get the information you need to construct a compatible BufferedImage object.The same mechanism can be extended to a variety of output devices, including printers. For example, you could create a BufferedImage that is compatible with a specific printer, resulting in an image whose color space, depth and pixel layout allow it to be drawn efficiently to that printer.