Home : Course Map : Chapter 11 : Java :
Image Display
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

To display an image on a component, we have used the Graphics class method

boolean drawImage (Image img, int x, int y, ImageObserver io)

Here the position of the top left corner of the image is specified by the x and y values. The width and height of the drawn image go according to the image's dimensions. If this is less than the drawing area, the background color of the component is visible in the uncovered regions. If the image is larger than the component area, then the portion of the image outside the component won't be seen.

The x and y values can actually be negative, in effect moving the top left corner of the image up and/or to the left of the drawing area. In such a case, only the region of the image within the component area will be visible.

Scaled images can be drawn with

  boolean drawImage(Image img, int x, int y,
                    int width, int height, ImageObserver observer)

where the width and height and be larger or smaller than the given size of the image, thus expanding or shrinking the image.

The method

boolean drawImage (Image img,
                   int dx1, int dy1,
                   int dx2, int dy2,
                   int sx1, int sy1,
                   int sx2, int sy2,
                   Color bg_color, ImageObserver io)

specifies that the rectangle between the corners sx1,sy1 and sx2,sy2 of the source image is drawn into the rectangle specified by the corners dx1,dy1 and dx2,dy2 of the destination image. The areas not covered in the destination component are painted with the color specified by the bg_color parameter.

Sections of an image can be copied into other parts of the screen method (useful for tiling)

  void copyArea(int x, int y,
     int width, int height,
     int destDx, int destDy)

You can also obtain a new Image object that represents a scaled version of an image with the getScaledInstance() method as in

..
Image img = getImage (url);
Image scaled_img = getScaledInstance (width, height, hints);

Here the new image referenced by scaled_img will have the width and height as given in the first two parameters. The type of scaling algorithm used depends on the third hints parameter. For example, the constant

Image.SCALE_AREA_AVERAGING

indicates that averaging around each point in the image should be used for the scaling. The Image class offers five options for scaling (see the class specification for details).

 

References & Web Resources

 

 

Latest update: Dec.1, 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.