Tuesday, July 26, 2011

Android - Matrix Pre, Post and Set methods

Matrix provide pre, post and set method for matrix transformation.

Pre and post are generally used to concatenate the existing Matrix value.

Set is used to overwrite the current matrix value with the existing ones.

But, please use Set method with care. It seems that Set methods will overwrite all the value in the 3x3 matrix. So, if you perform a postScale, then a setTranslate, the value set by postScale will be gone.

So, if you really want to set a translate with respect to x=0 and y=0, you can try the following

The following is trying to concat a scale, then perform a translation with respect to (0,0)

Matrix m = new Matrix();
//do a scale and post concat
m.postScale(2.0f, 2.0f);
//get the existing 3x3 matrix values
float mVal[] new float[9];
// erase the current value before concat new value
m.postTranslate(-mVal[Matrix.MTRANS_X], 0);
m.postTranslate(100.0f, 0);


  1. I am new to android.So any help is really a life saver for me.As you gave tip about set operation and shared the sample code.Thanks I was looking for same.
    electronic signatures

  2. ldap online training| ldap training| call us+919000444287 ...
    LDAP Online Training, LDAP training, LDAP course contents, LDAP , call us: +919000444287,dharani@21cssindia.com.


Windows 7 - STOP 0x0000007B (0xFFFFF880009A97E8 0xFFFFFFFFC0000034 0x0000000000 0x0000000000)

If you encounter STOP 0x0000007B (0xFFFFF880009A97E8 0xFFFFFFFFC0000034 0x0000000000 0x0000000000) blue screen of death. This is very like...