All of the image objects supported by WFC (Metafile, Icon, Bitmap, and Cursor) support the drawStretchTo and drawTo methods. All image rendering performed by the Graphics object occurs through these methods. When you call the Graphics object’s drawImage method, the object determines whether to call the drawStretchTo or the drawTo method on the image object that you pass the method.
The drawStretchTo method expands or shrinks an image to fit within a specified rectangular area. The drawTo method renders an image to a specified area also, but if the image is too large for the target area, the drawTo method clips it. In addition, both of these methods support drawing sections of an image to a specified section of the Graphics object’s bounding rectangle.
You cannot call the drawStretchTo or drawTo methods directly; they are always defined as protected methods in WFC image classes. To determine which of these methods is called, you call a version of the drawImage method that takes a boolean scale parameter. The following is one such method defined by the Graphics object:
public final void drawImage( Image i, Rectangle r, boolean scale )
If the scale parameter is true, the image is stretched or shrunk to fit the clipping rectangle; otherwise, the image is clipped.