Home Segments Top Top Previous Next

869: Mainline

The definition of paint shown in Segment 868 works, but it is likely to distort the image, because the height-to-width ratio of the image will differ from the height-to-width ratio of the component in which the image is to be displayed.

Accordingly, you might choose to use the getWidth and getHeight methods to obtain the width and height of the image, so that you can adjust the arguments provided to drawImage. The getWidth and getHeight methods each use an image as the target, and because the getWidth and getHeight methods need to know about the image-displaying properties of the component on which the image is to be drawn, that component, the value of this, is supplied as well, as an ordinary argument.

  *-- Image      *-- Component 
  v              v 
image.getWidth(this)