problems with affine transform scale.

R

Rajesh.Rapaka

HI all,

I am trying to use java's affine transform method for my zoom - in and
zoom - out functions. This is a small piece of code that i've written
in my "mouseClicked" mouse lisetner function.

AffineTransform tx = new AffineTransform();
AffineTransformOp op;
if (me.isMetaDown()) {
tx.scale(0.5, 0.5);
}
else {
tx.scale(1.5, 1.5);
}
op = new AffineTransformOp(tx,
AffineTransformOp.
TYPE_NEAREST_NEIGHBOR);
try {
bufImage = op.filter(bufImage, null);
}
catch (Exception e) {
e.printStackTrace();
}

It's working fine. But the more I do the zoom-in and zoom-out clicks
the images gets distorted. I understand its because of the scale. i am
not able to get back to the exact zoomed-out place after I zoomed-in.
for example lets say I zoomed from 5 to 10. and when i say zoom-out it
might be getting back to 3 or might be getting back to 8. but not to 5.


How can I solve this. What could be the exact values ? How can we know
it ?

plz help. Thanks in Advance.
regards,
Rajesh Rapaka.
 
A

Antti S. Brax

I am trying to use java's affine transform method for my zoom - in and
zoom - out functions. This is a small piece of code that i've written
in my "mouseClicked" mouse lisetner function.
It's working fine. But the more I do the zoom-in and zoom-out clicks
the images gets distorted. I understand its because of the scale. i am
not able to get back to the exact zoomed-out place after I zoomed-in.

No. It is because you perform operations on an already
manipulated image. Keep a reference to the original image
and scale it instead and store the current scale in a
variable.
 
C

Chris Smith

Antti S. Brax said:
No. It is because you perform operations on an already
manipulated image. Keep a reference to the original image
and scale it instead and store the current scale in a
variable.

In addition, note that 0.5 and 1.5 are NOT reciprocals of each other.
If you want a zoom in followed by a zoom out to get you back to normal,
then your scaling factors need to be reciprocals of each other. If you
scale something by 0.5, and then by 1.5, you'll get a final scale factor
of 0.75, NOT 1.0.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Antti S. Brax

In addition, note that 0.5 and 1.5 are NOT reciprocals of each other.
If you want a zoom in followed by a zoom out to get you back to normal,
then your scaling factors need to be reciprocals of each other. If you
scale something by 0.5, and then by 1.5, you'll get a final scale factor
of 0.75, NOT 1.0.

Exactly. If you want to scale something with factor X, then scaling
back is done with factor 1/X.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top