[3740] in java-interest
Re: What do x,y in java.awt.Graphics.drawImage() refer to?
daemon@ATHENA.MIT.EDU (Jim.Graham@Eng.Sun.COM)
Fri Nov 24 22:30:11 1995
Date: Fri, 24 Nov 1995 16:41:31 -0800
To: irogers@biggun.com
Cc: java@mt.e-technik.uni-kassel.de, java-interest@java.Eng.Sun.COM,
thwendt@mt.e-technik.uni-kassel.de, jvillaci@cs.indiana.edu
From: Jim.Graham@Eng.Sun.COM
The x,y in drawImage refer to the location on the screen (relative to
the origin or translation of the Graphics object) at which to draw
the upper left corner of the image.
The reason this is confusing in the "drawing a subset of an image"
example you have is that if you want pixel i,j of the image to appear
at 0,0 which is also the upper left corner of the clipping rectangle,
then you have to draw the image at screen location -i,-j so that the
screen location 0,0 is i pixels from the left edge of the image and j
pixels from the top edge of the image - thus screen location 0,0 shows
image pixel i,j...
If you want to draw imgX, imgY, imgW, imgH subset of an image at
scrX, scrY, then do the following:
g.clipRect(scrX, scrY, imgW, imgH);
g.drawImage(img, scrX-imgX, scrY-imgY, this);
Note that this permanently changes the clip rectangle of the g object.
If you want to avoid modifying g that way, then this is equivalent to:
Graphics subg = g.create(scrX, scrY, imgW, imgH);
// Note that subg has been translated by scrX, scrY
// so that (scrX, scrY) in g is at (0, 0) in subg
subg.drawImage(img, -imgX, -imgY, this);
subg.dispose();
except that in the second case, the original g object has its clipRect
left undisturbed.
...jim
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com