wood burning stoves*
The moose likes Other JSE/JEE APIs and the fly likes Java2D: Diff between TranslateInstance and ScaleInstance AffineTransform Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Java2D: Diff between TranslateInstance and ScaleInstance AffineTransform" Watch "Java2D: Diff between TranslateInstance and ScaleInstance AffineTransform" New topic
Author

Java2D: Diff between TranslateInstance and ScaleInstance AffineTransform

Chris Jebaraj
Ranch Hand

Joined: Sep 19, 2003
Posts: 34
Hi Guys!

When i do some image processing stuffs, I came across two code snippets..

Fliping the image horizontally:
-------------------------------
AffineTransform tx = AffineTransform.getScaleInstance(-1, 1);
tx.translate(-image.getWidth(null), 0);

Scale the image:
----------------
AffineTransform tx = AffineTransform.getTranslateInstance(image.getWidth(null), 0);
tx.scale(iScaleX, iScaleY);


I really do not understand what is the difference between these two code snippets. First one: Get the scale instance and apply tranlation and in Second one: get the translation instance and apply scale. I am totally confused here . I tried with the other way round for the both case. it's working fine. In that case, why we need two ways to achive. Is there any special reason or any significant advantage in these.

Please clear me. Thanks everybody.


JebaRaj.<br /> MCP, SCJP 1.5 <br />----------------------------<br /> THOUGH TIMES TEACH TRUST. <br />----------------------------
marcus g.
Greenhorn

Joined: Nov 10, 2003
Posts: 9
The order of operations in an AffineTransform matters.
In some cases you might not see any difference, as you say from your code snippets.


If you try more complex examples you will notice that the results will vary.

In essence a backend multiplication of matrices will be different if you have matriceA * matriceB vs matriceB * matriceA

Regards
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Java2D: Diff between TranslateInstance and ScaleInstance AffineTransform
 
Similar Threads
Shape.getPathIterator() called w/ null AffineTransform
Why can't I use getScaledInstance to scale images?
Resizing Large JPG Problem
Scaling image: black box until repainting
poor gui performance