Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java2D: Diff between TranslateInstance and ScaleInstance AffineTransform

 
Chris Jebaraj
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
marcus g.
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic