Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DrawImage Question

 
Mike London
Ranch Hand
Posts: 1158
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 1158
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
-- Mike
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic