This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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 ]