Looking for an explanation of post/pre/set Translate (in Matrix object) and how to use them

AndroidMatrixBitmapAndroid Canvas

Android Problem Overview


The documentation is pretty vague as to what is actually happening when these methods are used. Can someone explain how Matrix actually affects the Bitmap that it's being set to? They use the term concatenate in there, but I'm unclear on how that term applies to coordinate data (having only used it in regard to string manipulation before).

Android Solutions


Solution 1 - Android

The set-methods will replace the current Matrix with new values, disregarding whatever the Matrix contained before. The pre and post method will apply a new transformation before or after whatever the current Matrix contains.

In this example, the rotation will be ignored since we are using the set method and the m will only contain a translation:

> Matrix m = new Matrix(); > > m.setRotate(90); > > m.setTranslate(100, 100);

In this example, the final matrix will be a translation followed by a rotation:

> Matrix m = new Matrix(); > > m.setTranslate(100, 100); > > m.postRotate(90);

In the final example, the final matrix will be a rotation followed by a translation:

> Matrix m = new Matrix(); > > m.setTranslate(100, 100); > > m.preRotate(90);

There is some more information in this (rather lengthy) post:

http://www.satyakomatineni.com/akc/display?url=displaynoteimpurl&ownerUserId=satya&reportId=2898

Hope it helps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionYevgeny SimkinView Question on Stackoverflow
Solution 1 - AndroidAlbinView Answer on Stackoverflow