Hello,

I got a problem of using the AffineTransform object.
This is what I did:

I created an AffineTransform object then invoke the
setToScale(double, doble) method for scaling purposes
of drawing an image.  It works fine, but I would like to
do something more that scaling only.  I like to translate
the origin of drawing the image, and I called the
translate( double, double) method, but it seems that
it's not working well.  So I tried to verify the values
of the translation in the paint method using the
getTranslateX( ) and getTranslateY( ), and I found
out that it is not the same values that I set using
the translate( double, double) method.

Could someone explain it to me why?

BTW, here are some snippets to refer:

--start--

    public void paint( Graphics g )
    {
        super.paint( g );
        Graphics2D g2 = (Graphics2D) g;
        g2.drawImage( image, af, this );
    }

    public void zoom( int zoomSize )
    {
        double zoomRatio  = zoomSize * 0.1 + 1;
        int width  = (int) ( image.getWidth( this ) * zoomRatio );
        int height = (int) ( image.getHeight( this ) * zoomRatio );

        if ( zoomSize >= 0 )
        {
            Dimension newSize = new Dimension( width, height );
            setSize( newSize );
            setPreferredSize( newSize );
        }
        else
        {
            double x = (double) ( getSize( ).width - width ) / 2;
            double y = (double) ( getSize( ).height - height ) / 2;
            af.setToTranslation( x, y );
        }
        af.setToScale( zoomRatio, zoomRatio );
        repaint( );
    }

    public void translate( int zoomSize )
    {
        double zoomRatio  = zoomSize * 0.1 + 1;
        int width  = (int) ( image.getWidth( this ) * zoomRatio );
        int height = (int) ( image.getHeight( this ) * zoomRatio );

        if ( zoomSize < 0 )
        {
            double x = (double) ( getSize( ).width - width ) / 2;
            double y = (double) ( getSize( ).height - height ) / 2;
            af.translate( x, y );
        }
        repaint( );
    }

--end--

--
Charlemagne L. Rey
Software Design Engineering
NEC Technologies Philippines, Inc.
--do unto others as you would have them do unto you--


=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 2D Home Page: http://java.sun.com/products/java-media/2D/

Reply via email to