gpt4 book ai didi

android - 在 Canvas 上绘制两个 3D 字符串?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:51:03 30 4
gpt4 key购买 nike

我必须在 Canvas 上绘制 2 个字符串。字符串必须使用相同的坐标 绘制,第二个字符串必须是第一个字符串绕轴 Y 旋转 45 度的结果。结果必须如下所示:

enter image description here

这是我的代码:

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);

但是上面代码的结果是:

enter image description here

可以看到字符串的坐标不一样,那我做错了什么?我猜是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);

对于以上所有三个代码,结果如下所示:

enter image description here

我猜第二个文本绘制在范围之外或在 状态栏 后面,因此它不可见。

然后将我的代码更改为:

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);

结果:

enter image description here

最佳答案

感谢回复。我解决了问题。我必须使用 canvas.concat() 而不是 canvas.setMatrix。这是正确的代码:

Matrix matrix = new Matrix();
mCamera = new Camera();

canvas.drawText("In the name of God", 30, 100, redPaint);
mCamera.rotateY(60);
mCamera.getMatrix(matrix);

matrix.preTranslate(-30, -100);
matrix.postTranslate(30, 100);
canvas.concat(matrix);
canvas.drawText("In the name of God", 30, 100, greenPaint);

关于android - 在 Canvas 上绘制两个 3D 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13438032/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com