赞
踩
我必须在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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。