Meaningless Drivel is fun!*
The moose likes Swing / AWT / SWT and the fly likes DrawImage Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "DrawImage Question" Watch "DrawImage Question" New topic

DrawImage Question

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
I'm trying to center one image (the 'f' suffix below) onto another background image (the 'b' suffix below).
((heightB + heightf)/2),
((widthB - widthf)/2),
((widthB - widthf)/2),
((heightB - heightf)/2),,
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?
What about y?
I really appreciate anyone's help.
-- Mike
raj madhuram
Ranch Hand

Joined: Oct 10, 2001
Posts: 71
(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,
[ April 10, 2003: Message edited by: raj madhuram ]
[ April 10, 2003: Message edited by: raj madhuram ]
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1043
-- Mike
wood burning stoves
subject: DrawImage Question
Similar Threads
cropping image in a servlet
Resetting or Undoing AffineTransforms
Improving Graphics
Image Observer
how to reverse an image?