Documents in about Canvas.setMatrix() say:
Completely replace the current matrix with the specified matrix. If
the matrix parameter is null, then the current matrix is reset to
identity.
And about Canvas.concat() say:
Preconcat the current matrix with the specified matrix.
But It seems surd.When I tried this code:
Matrix matrix = new Matrix();
mCamera = new Camera();
canvas.save();
mCamera.rotateY(y_rotate_angle);
mCamera.getMatrix(matrix);
canvas.concat(matrix);
canvas.drawText(text, 30, 100, redPaint);
// canvas.restore();
canvas.setMatrix(null);
canvas.setMatrix(matrix);
canvas.drawText(text, 30, 100, greenPaint);
In result,second text will drawn at (60,100) instead of drawing at (30,100)(even when I tried canvas.restore() and comment canvas.setMatrix).
It is strange!I get matrix of canvas before saving it and then print it’s members.I guessed that it be
IDENTITYmatrix,but it was not!So when I didsetMatrix(null),the matrix of canvas was set by a matrix that was not equal to original matrix of canvas and this caused problems.