Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.graphics.Matrix -> How does postScale work

Tags:

android

Good afternoon,

Lets say I have a Matrix. I have 2 values, .9 for zooming out and 1.1 for zooming in.

When I apply the matrix.postScale(0.9, 0.9); 3 times Then I apply the matrix.postScale(1.1, 1.1); 3 times

I am not back where I started!!

for example, here are the results I recorded:

Current Scale postScale (x, x) Resulting Scale

1                  .9               .9
.9                 .9               .80999994
.80999994          .9               .7189999

.7189999           1.1              .8018999
.8018999           1.1              .8820899
.8820899           1.1              .97029895

As you can see I'm not back to 1. What is going on, am I getting the current scale incorrectly?

For example, to get all the values on the right, I preformed this after the postScale was applied:

matrix.getValues(tempArrayFloat);
Number = tempArrayFloat[Matrix.MSCALE_X];

I just assumed that the MSCALE_X and MSCALE_Y would be the same?

My question is, if I scale a matrix using 1 specific value 3 times, .9 -> .9 -> .9, what number do I need to scale it back to it's original position?

-Kind Regards,

Paul

like image 638
Killesk Avatar asked May 20 '26 22:05

Killesk


2 Answers

The numbers in the right hand side of your table give you your answer, a scaling matrix multiplies points by the scaling value. So applying matrix.postScale(0.9) three times scales by 0.9*0.9*0.9 = 0.729. Applying matrix.postScale(1.1) three times scales by 1.1*1.1*1.1=1.331. To get back where you started, you need to scale by 1.0/0.729=1.372

like image 90
Andrew Marshall Avatar answered May 22 '26 10:05

Andrew Marshall


Scale it back by using 1.111111112 instead of 1.1, but if you are scaling a bitmap it may be easier to resize it to a round value.

Basically you could state matrix.postScale(1.0/0.9, 1.0/0.9); this should round it to the nearest pixel

like image 24
Lumis Avatar answered May 22 '26 11:05

Lumis