Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

problems with affine transform scale.

Thread view: 
Rajesh.Rapaka - 15 Jun 2005 13:19 GMT
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.
Antti S. Brax - 15 Jun 2005 13:52 GMT
rajesh.rapaka@gmail.com wrote in comp.lang.java.programmer:
> 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.
<snip>
> 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.

Signature

Antti S. Brax                  Rullalautailu pitää lapset poissa ladulta
http://www.iki.fi/asb/         http://www.cs.helsinki.fi/u/abrax/hlb/

              [1385 messages expunged from folder "Spam"]

Chris Smith - 15 Jun 2005 15:49 GMT
>     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.

Signature

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Antti S. Brax - 16 Jun 2005 06:45 GMT
cdsmith@twu.net wrote in comp.lang.java.programmer:
> 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.

Signature

Antti S. Brax                  Rullalautailu pitää lapset poissa ladulta
http://www.iki.fi/asb/         http://www.cs.helsinki.fi/u/abrax/hlb/

              [1385 messages expunged from folder "Spam"]



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.