Hello,

Does anyone have a good snippet for panning and zooming which will keep the
current center of the image centered when zooming?

I want to be able to display a buffered image and be able to zoom in/out,
pan it, and rotate it.

Looks like I will need to adjust the translateX and translateY when my zoom
factor changes.

Thank you,

Ted Hill



This is what I have so far:

/////////////////////////////////
    private AffineTransform getTransform( )
    {
        AffineTransform atx = new AffineTransform( );

        // respond to pan
        if(bPanning)
        {
            panX += deltaX;
            panY += deltaY;
        }
        else // zooming
        {
            if(deltaY > 0)
            {
                zoomFactor -= 0.1;
            }
            else if(deltaY < 0)
            {
                zoomFactor += 0.1;
            }
        }

        atx.translate(panX, panY);
        atx.scale(zoomFactor, zoomFactor);

        return atx;
    }

    protected void paintComponent(Graphics g)
    {
        super.paintComponent(g);

        Graphics2D g2 = (Graphics2D) g;

        AffineTransform atx = getTransform( );

        g2.drawImage(bufferedImage, atx, this);
    }

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to