当前位置:   article > 正文

android 多个canvas,android – 在Canvas上绘制两个3D字符串?

android canvas 立体字

我必须在canvas上绘制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);

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

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

然后将我的代码更改为:

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

结果:

解决方法:

试试这个:

Matrix matrix = new Matrix();

matrix = canvas.getMatrix();

mCamera = new Camera();

canvas.drawText("In the name of God", 30, 100, redPaint);

mCamera.translate(30, 100);

mCamera.rotateY(45);

mCamera.getMatrix(matrix);

canvas.setMatrix(matrix);

canvas.drawText("In the name of God", 0, 0, greenPaint);

我从不弄乱翻译前和翻译,但你可以调试它并尝试进行翻译而不是预翻译并提供(30,100)并查看是否有效.

标签:android,camera,matrix,android-canvas

来源: https://codeday.me/bug/20190620/1246869.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/185849
推荐阅读
相关标签
  

闽ICP备14008679号