Home : Course Map : Chapter 11 : Java :
The java.awt.Image Class
JavaTech
Course Map
Chapter 11

Introduction
Image Class
Image Loading
  Demo 1 Demo 2  
Pixels/Transparency
  Demo 3
Pixel Handling
  Demo 4  
Demo 5
Exercises

    Supplements
Java 2D Imaging
BufferedImage
Creating Buf.Image
Pixel Handling
  Demo 1 Demo 2
Filters
  Convolutions
     Demo 3
  AffineTransforms
     Demo 4
  LookupTable
     Demo 5 Demo 6
  Rescale
     Demo 7
  Color Conversion
     Demo 8
  Custom
     Demo 9
Exercises
Java Adv Imaging
AWT Flicker:
  Override Update
     Demo 1  Demo 2
  Clipping
     Demo 3
  Double Buffer
     Demo 4

     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

We briefly discussed the java.awt.Image class in Chapter 6: Java : Images. There we showed how to create an instance of the Image class by loading an image file.

The java.awt.Image class is actually abstract. However, methods such as getImage(URL) in the Applet class return an instance of a concrete subclass provided by the particular JVM implementation. The details of that subclass are not important since you invoke only methods listed in the Image class, many of which are overridden by the subclass.

The BufferedImage subclass of Image, on the other hand, is accessible to the user and it offers many features not available with Image. We discuss BufferedImage in the Chapter 11: Supplements section on Java2D image processing techniques.

The Image class provides only minimal access to information about the image. It does include the methods

  int getWidth (ImageObserver)
  int getHeight (ImageObserver)

that return the dimensions of an image.

You can draw on an image just as you would draw on a component by obtaining the graphics context object via the Image class method

  Graphics getGraphics ()

You then invoke the usual drawing methods in the Graphics object to draw on the image.

You can create an image just to draw on it using the createImage() method from the Component class as in the following snippet:

 ...
Image image = createImage (width, height);
Graphics g = image.getGraphics ();
paint (g); // Your paint() method does the usual drawing operations
           // but on the image rather than on a component.

Such an off-screen image has the advantage of fast execution. For example, all of the operations needed to draw a frame in an animation can first be peformed on an off-screen image and then the image is sent to the visible component in one operation. This double-buffering technique is discussed further in Chapter 11: Supplements: AWT Flicker where it is used to reducing the flickering in animations with the AWT components. (Swing components use double-buffering by default.)

We discuss in Pixel Handling how to access the individual pixels in an Image object. We also look at how to create Image objects from pixel arrays.

References & Web Resources

 

 

Last update: Dec. 3, 2004

              Tech
Fractals
Fractal Drawing
   Demo 1
Fractal Draw Code
Fractal Images
  Demo 2
Image Processing
  Demo 3
Histogram Image
  Demo 4
Exercises

           Physics
Calibration/SysError
SimWithCal/SysErr
  Demo 1
Analysis
  Demo 2
Examples

Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.