我必须在画布上绘制 2 个字符串。字符串必须使用相同的坐标绘制,第二个字符串必须是第一个字符串绕 Y 轴旋转 45 度的结果。结果必须如下所示:
这是我的代码:
Matrix matrix = new Matrix();
matrix = canvas.getMatrix();
mCamera = new Camera();
canvas.drawText("In the name of God", 30, 100, redPaint);
mCamera.rotateY(45);
mCamera.getMatrix(matrix);
matrix.preTranslate(30, 100);
// matrix.postTranslate(-30, -100);
canvas.setMatrix(matrix);
canvas.drawText("In the name of God", 0, 0, greenPaint);
但是上面代码的结果是:
你可以看到字符串的坐标是不同的。那么我做错了什么?我猜这是由不正确的参数引起的matrix.preTranslate()
。
更新:
我将代码更改为:
canvas.drawText("In the name of God", 30, 100, redPaint);
mCamera.rotateY(45);
mCamera.getMatrix(matrix);
matrix.preTranslate(-30, -100);
matrix.postTranslate(30, 100);
canvas.setMatrix(matrix);
canvas.drawText("In the name of God", 0, 0, greenPaint);
或喜欢:
canvas.drawText("In the name of God", 30, 100, redPaint);
mCamera.rotateY(45);
mCamera.getMatrix(matrix);
matrix.preTranslate(-30, -100);
//matrix.postTranslate(30, 100);
canvas.setMatrix(matrix);
canvas.drawText("In the name of God", 0, 0, greenPaint);
或喜欢:
canvas.drawText("In the name of God", 30, 100, redPaint);
mCamera.rotateY(45);
mCamera.getMatrix(matrix);
matrix.preTranslate(-30, -100);
// matrix.postTranslate(30, 100);
canvas.setMatrix(matrix);
canvas.drawText("In the name of God", 30, 100, greenPaint);
对于上述所有三个代码,结果如下所示:
我猜第二个文本超出了范围或在后面status bar
,所以它是不可见的。
然后将我的代码更改为:
mCamera.rotateY(45);
mCamera.getMatrix(matrix);
matrix.preTranslate(-30, -100);
matrix.postTranslate(30, 100);
canvas.setMatrix(matrix);
canvas.drawText("In the name of God", 30, 100, greenPaint);
结果: