This week's book giveaway is in the Design forum.We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!

# DrawImage Question

Mike London
Ranch Hand
Posts: 1190
4
I'm trying to center one image (the 'f' suffix below) onto another background image (the 'b' suffix below).
gOut.drawImage(imageFore,
((heightB + heightf)/2),
((widthB - widthf)/2),
((widthB - widthf)/2),
((heightB - heightf)/2),
Color.red,
null);
My confusion is what do the coordinates mean.
The above code is from the drawImage form:
public boolean drawImage(Image img, int x, inty, int width, int height)
The Sun docs say: "x is the x-coordinate", "y is the y-coordinate".
This code will draw a rectangle with an image onto another image.
Is x the upper left corner of the outer region or the inner rectangle that will be drawn?
I really appreciate anyone's help.
Thanks.
-- Mike

Ranch Hand
Posts: 71
Hi,
(x,y) is the upper left corner coordinate of the image you want to place. This is relative to the graphics context's coordinate space.
You can simply use the drawImage( Image img, int x, inty, ImageObserver observer) method if you want to place the entire foreground image. This is how you might do this:
Let (Xb, Yb) be the top-left corner coordinate of the background image.
The foreground image has to be drawn at an offset ((widthB - widthf)/2, (heightB - heightf)/2). So the method call will look like:

Hope that helps,
Raj
[ April 10, 2003: Message edited by: raj madhuram ]
[ April 10, 2003: Message edited by: raj madhuram ]

Mike London
Ranch Hand
Posts: 1190
4
Thanks.
-- Mike