Hello,
I am working on an imaging application.
One panel presents a BufferedImage and allows the user to scale, translate,
and rotate the image.
Once users have the image transformed to their liking, they can draw on top
of the image.
One of the drawing functions outlines a portion of the transformed image
with filled circles (dots).
Because the image can be scaled differently in the x and y directions and
can be rotated, the dots are drawn on top of the transformed image using the
identity transform so that they will
1) always be round
2) remain the same size (though not at the same location) when the
underlying image is rescaled.
A simplified version of my paintComponent() code looks something like this:
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
AffineTransform origAtx = g2.getTransform( );
// apply the user's chosen transform
g2.transform(getUserTransform());
// draw the buffered image with the user's transform
g2.drawImage(baseImage, 0, 0, this);
// set the identity transform for drawing
g2.setTransform( new AffineTransform()); // this works but is
FORBIDDEN! in 1.4 JavaDoc
// draw on top of the transformed image using the identity transform
drawOnTopOfImage(g2);
g2.setTransform(origAtx);
}
I have noticed that the Java Doc for 1.4 says the following about
setTransform():
=================== start JavaDoc
public abstract void setTransform(AffineTransform Tx) Overwrites the
Transform
in the Graphics2D context. WARNING: This method should never be used to
apply a new coordinate transform on top of an existing transform because
the Graphics2D might already have a transform that is needed for other
purposes, such as rendering Swing components or applying a scaling
transformation to adjust for the resolution of a printer.
To add a coordinate transform, use the transform, rotate, scale, or
shear methods. The setTransform method is intended only for restoring
the original Graphics2D transform after rendering, as shown in this
example:
// Get the current transform
AffineTransform saveAT = g2.getTransform();
// Perform transformation
g2d.transform(...);
// Render
g2d.draw(...);
// Restore original transform
g2d.setTransform(saveAT);
===================== end Java Doc
So my question is:
Is there a recommended way to draw on top of a transformed image using the
identity transform?
Is there some way to derive an inverse transform from the current user
transform, so that I could draw using the identity transform by calling
g2.transform(inverseOfUserTransform);
Thanks for your help,
Ted Hill
===========================================================================
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".