aspose file tools*
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "DrawImage Question" Watch "DrawImage Question" New topic
Author

DrawImage Question

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
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?
What about y?
I really appreciate anyone's help.
Thanks.
-- Mike
raj madhuram
Ranch Hand

Joined: Oct 10, 2001
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

Joined: Jul 12, 2002
Posts: 1034
Thanks.
-- Mike
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DrawImage Question
 
Similar Threads
Image Observer
Improving Graphics
Resetting or Undoing AffineTransforms
how to reverse an image?
cropping image in a servlet