Creating Images

AWT components, in addition to being image observers, are also capable of creating images. java.awt.Component comes with two methods for creating images:

  • createImage(ImageProducer)

  • createImage(int width, int height)

The first version of createImage() creates an image, given an ImageProducer from which the bits of the image are obtained; we will find a use for this method in “Loading Images as Resources”.

The second version creates an image suitable for an offscreen buffer, as we shall discover in “Double Buffering”.

Additionally, the java.awt.Toolkit class is also capable of creating images and provides the following methods:

  • createImage(ImageProducer)

  • createImage(byte[] bits)

  • createImage(byte[] bits, int offset, int length)

Like ...

Get Graphic Java™ 1.2, Volume I: AWT, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.