Java Reference
In-Depth Information
The various ways of calling drawImage are described below. They all expect an
instance of ImageObserver as one of the arguments. As discussed in Section 15.4.1
we can use this here. In the following, we assume that we draw into a panel, the
procedure remains the same for other components which can display images.
drawImage(Image picture, int left, int top, ImageObserver imo)
drawImage(Image picture, int left, int top, int width, int height,
ImageObserver imo)
drawImage(Image picture, int tl, int tt, int tr, int tb, int sl,
int st, int sr, int sb, ImageObserver imo)
drawImage(Image picture, int left, int top, ImageObserver imo) has
already been described in Section 15.4.1. It displays image picture such that
its upper left corner is at pixel coordinates left and top of the panel.
drawImage(Image picture,int left,int top, int width, int height, Image-
Observer imo) draws image picture , such that its upper left corner is at
pixel coordinates left and top in the panel. The displayed image is width
pixels wide and height high. The image is shrunk or stretched to match these
constraints. It is important to note that the image itself, i.e. the content of
!
variable picture ,is not changed. The resizing is only in the display.
drawImage(Image picture, int tl, int tt, int tr, int tb, int sl, int
st, int sr, int sb, ImageObserver imo) draws a rectangular clip of the
image picture into a rectangular target area of the panel. The integer values
tl , tt , tr and tb specify, respectively, the pixel coordinates of the left,
!
top, right and bottom edges of the target rectangle. The values sl , st , sr
and sb specify, respectively, the pixel coordinates of the left, top, right and
bottom edges of the source rectangle in picture . The width and height of
the source rectangle do not have to match the corresponding values of the
target rectangle; the clip will be resized to fit into the target area. See also
Figure 15.3.
These commands can also be used to reflect an image. If one chooses a negative
value for argument width in the second drawImage method then the image will
!
be vertically reflected. The displayed image has a width that is the absolute value
of argument width but left and right are interchanged. Using a negative value
for height results in a horizontal reflection. This also affects the meaning of the
parameters left or top . These always reference the position of the upper left
corner of the original picture . After a vertical reflection this becomes the upper
right corner of the displayed image.
Also the last drawImage method can be used to reflect the clipped part. Here,
( sl
,
st ) (the upper left corner of the source rectangle) is always mapped onto ( tl
,
tt )
(the upper left corner of the target rectangle). Similar for ( sr
,
sb ) and ( tr
,
tb ). In an
unreflected display we have sl
tb .Tovertically reflect
the clipped area one only has to swap left and right by choosing tr
<
sr , st
<
sb , tl
<
tr , tt
<
tl , i.e. by
choosing the 'right' edge of the target left of its 'left' edge. For a horizontal reflection
tt
<
>
tb is set.
Search WWH ::




Custom Search