gpt4 book ai didi

android - 在 Canvas 中旋转文本

转载 作者:行者123 更新时间:2023-11-29 14:18:30 25 4
gpt4 key购买 nike

如何旋转 Canvas 中的文本?我需要翻转我颠倒的文字。

paint.setTextSize(20); 
canvas.drawText("3AM", xStored, yStored, paint);

最佳答案

引用这个link

 int x = 75;
int y = 185;
paint.setColor(Color.GRAY);
paint.setTextSize(25);
String rotatedtext = "Rotated helloandroid :)";

//Draw bounding rect before rotating text:

Rect rect = new Rect();
paint.getTextBounds(rotatedtext, 0, rotatedtext.length(), rect);
canvas.translate(x, y);
paint.setStyle(Paint.Style.FILL);

canvas.drawText(rotatedtext , 0, 0, paint);
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(rect, paint);

canvas.translate(-x, -y);


paint.setColor(Color.RED);
canvas.rotate(-45, x + rect.exactCenterX(),y + rect.exactCenterY());
paint.setStyle(Paint.Style.FILL);
canvas.drawText(rotatedtext, x, y, paint);

关于android - 在 Canvas 中旋转文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20572572/

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