O'Reilly logo

Graphic Java™ 1.2, Volume I: AWT, Third Edition by David M. Geary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required