https://code.google.com/p/android/issues/detail?id=93367
When using Canvas.getMarix Android Studio stikes it out and hints as deprecated. In Canvas.class it’s really declared with @java.lang.Deprecated. But in documentation on page http://developer.android.com/intl/ru/reference/android/graphics/Canvas.html#getMatrix(android.graphics.Matrix) nothing is written about it, so developer does not know why it is deprecated and what is better to use instead.
The same situation with Canvas.drawPosText
https://developer.android.com/reference/android/graphics/Canvas.html?hl=ru#getMatrix(android.graphics.Matrix)
getMatrix
Added in API level 1
void getMatrix (Matrix ctm)
This method was deprecated in API level 16.
Hardware accelerated canvases may have any matrix when passed to a View or Drawable, as it is implementation defined where in the hierarchy such canvases are created. It is recommended in such cases to either draw contents irrespective of the current matrix, or to track relevant transform state outside of the canvas.
Return, in ctm, the current transformation matrix. This does not alter the matrix in the canvas, but just returns a copy of it.
https://code.google.com/p/android/issues/detail?id=24517
Canvas getMatrix() and setMatrix() do not correspond when using hardware acceleration (hardwareAcceleration=“true” in Android manifest), i.e. calling canvas.setMatrix(canvas.getMatrix()) in onDraw changes the resulting drawing. This does not happen when hardwareAcceleration is switched off.
The same problem occurs, when using canvas.getMatrix(myMatrix); canvas.setMatrix(myMatrix), and when, between the calls to getMatrix() and setMatrix(), transformations are applied to the matrix. Simply applying transformations to the canvas (e.g. canvas.translate(10, 10)) work as expected.
It seems that the call to getMatrix() returns the matrix relative to the view the canvas belongs to, whereas setMatrix() set’s the matrix relative to the entire screen (including status bar, title bar, etc.). When, for example, drawing to an empty screen with just the Android status bar (the one that indicates notifications, battery level, time, etc.), coordinate (0, 0) seems to lie just below the status bar when not applying any matrices (or switching off hardware acceleration), but it seems to lie in the very top-left corner of the screen (i.e. the top left corner of the status bar) when doing described matrix operation and using hardware acceleration.
The expected behavior would be to have (0,0) lie right below the status bar, such as when not doing any matrix operations or switching off hardware acceleration.
I’ve attached a sample program that illustrates the problem. I’ve run the program on my Nexus Galaxy running Android 4.0.1.
To work around the problem, in most situations (such as mine), you can apply any transformations using canvas.scale(), canvas.translate(), etc. rather than retrieving the matrix, modifying it and then setting the matrix again.