Here are my last 3 duke dollars.  Can someone please help me draw a line?

I have been BEATING my head on this for well over a week now. I'm new to Java2D and I cannot find even one example of this simple little thing that I am trying to do. Not one.
All I want to do is draw an image, zoom that image, then draw some lines on that image, and then zoom it and have those lines show up where they should.
For example, we have an image which has been zoomed. No lines are yet drawn on it.
A line is added.
The image is then zoomed in or out one more time.
How do we get the line to remap to the newly zoomed image?
What I am doing is:
0) Load up an image from a file.
1) Create a zoomed image by using the Image.getScaledInstance() method.
2) Create a BufferedImage with the width and height of the image AFTER the zoom has taken place.
3) Create a Graphics2D object by the createGraphics from this BufferedImage.
4) Place the image into the BufferedImage by doing a BufferedImage.drawImage
5) Select two points to be the start and end of the line.
6) Draw the line using Graphics2D.drawLine(start.x, start.y, end.x, end.y).
7) Zoom the image again (using the Image.getScaledInstance() method.
8) Create a new ImageIcon using the image from above and override its paintIcon method like this:
ImageIcon newIcon = new ImageIcon(newImage) {                       
public void paintIcon(Component c, Graphics g, int x, int y)
super.paintIcon(c, g, x, y);
zoom(); //<---- ZOOM call
Now in the zoom routine, what do I need to do to get the lines to draw at the proper location and size?
Remember, the points of the lines (stored in a list as home grown line objects) are in screen coordinates, not image coordinates since they are just click points
Note that when I use these points to draw a line, all is well (the line gets drawn where it should), but I have problems when I zoom the image.
Thanks!

Below is the documentation and method signature of
Graphics.drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer);The important thing to note is that it does scaling on the fly if the size dictated by the source co-ordinates is defferent than the size dictated by the destination co-ordinates. The source image is always left un-touched.
So basically your visual data is located in an offscreen image. You can draw a line on that. Then create a new image, get it's graphics and call drawImage(original_image, co-ordinates that cause it to scale how you like).
Then you can draw lines on the 2nd image, create a 3rd, ...etc
     * Draws as much of the specified area of the specified image as is
     * currently available, scaling it on the fly to fit inside the
     * specified area of the destination drawable surface. Transparent pixels
     * do not affect whatever pixels are already there.
     * <p>
     * This method returns immediately in all cases, even if the
     * image area to be drawn has not yet been scaled, dithered, and converted
     * for the current output device.
     * If the current output representation is not yet complete then
     * <code>drawImage</code> returns <code>false</code>. As more of
     * the image becomes available, the process that draws the image notifies
     * the specified image observer.
     * <p>
     * This method always uses the unscaled version of the image
     * to render the scaled rectangle and performs the required
     * scaling on the fly. It does not use a cached, scaled version
     * of the image for this operation. Scaling of the image from source
     * to destination is performed such that the first coordinate
     * of the source rectangle is mapped to the first coordinate of
     * the destination rectangle, and the second source coordinate is
     * mapped to the second destination coordinate. The subimage is
     * scaled and flipped as needed to preserve those mappings.
     * @param       img the specified image to be drawn
     * @param       dx1 the <i>x</i> coordinate of the first corner of the
     *                    destination rectangle.
     * @param       dy1 the <i>y</i> coordinate of the first corner of the
     *                    destination rectangle.
     * @param       dx2 the <i>x</i> coordinate of the second corner of the
     *                    destination rectangle.
     * @param       dy2 the <i>y</i> coordinate of the second corner of the
     *                    destination rectangle.
     * @param       sx1 the <i>x</i> coordinate of the first corner of the
     *                    source rectangle.
     * @param       sy1 the <i>y</i> coordinate of the first corner of the
     *                    source rectangle.
     * @param       sx2 the <i>x</i> coordinate of the second corner of the
     *                    source rectangle.
     * @param       sy2 the <i>y</i> coordinate of the second corner of the
     *                    source rectangle.
     * @param       observer object to be notified as more of the image is
     *                    scaled and converted.
     * @return   <code>true</code> if the current output representation
     *           is complete; <code>false</code> otherwise.
     * @see         java.awt.Image
     * @see         java.awt.image.ImageObserver
     * @see         java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
     * @since       JDK1.1
    public abstract boolean drawImage(Image img,
                          int dx1, int dy1, int dx2, int dy2,
                          int sx1, int sy1, int sx2, int sy2,
                          ImageObserver observer);

Similar Messages

Maybe you are looking for

  • I have installed bridge 6. I have the icons and it shows in the directory, but will not open

    I have installed bridge cs6 and it will not open. I have the icons and it shows in the directory.  I open CS6 CC ok but when I open bridge from CS6, it opens the older virsion CS5.

  • System preference : engery don't function, system preference : engery don't function

    Hey, i have 2 big problems with lion: Nr. 1 : the part "save energy" in the system preferences don't function ! When i want to open it it crash and the preferences stopp and i have to "quit it directly" Nr. 2 : I can't send my MacBook Pro in the off

  • Auto start service problem with Xp

    i installed Oracle 8i (8.1.5) on window XP Pro. it was install ok. but when i am restarting the PC. it is not starting the database service autometic. i check all the values of auto service but i am failed to start it. so can anyone help me to solve

  • SDHC for back up disk

    Hi Is it possible to use SDHC (High Capacity) card with time machine? or if my MacBookPro SD slot support SDHC card? My mac is a MacBookPro with Snow Leopard. The card i want to use is this: http://www.sandisk.com/microsites/extremeteam/index.html Sa

  • ENT-06954: Error while Displaying BIBean for Cube Dataviewer.

    Hello, I need urgent help. I build a ROLAP cube using OWB 11g. First it works, but after 2 days when I want to view data cube, using Data Viewer I receive this error. Please help me. ENT-06954: Error while Displaying BIBean for Cube Dataviewer. ENT-0