旋转文本在画布 [英] Rotate Text in Canvas
本文介绍了旋转文本在画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你如何旋转文本是在画布?我需要翻转我有倒挂的文字。
paint.setTextSize(20);
canvas.drawText(上午03点,xStored,yStored,油漆);
解决方案
我从注释下接受答案的解决方案,通过罗曼盖伊
<一个href="http://stackoverflow.com/questions/2558257/how-can-you-display-upside-down-text-with-a-textview-in-android">How您可以显示颠倒的文本与Android的一个TextView?
引用您可以通过-1只是规模上的Y轴。
@覆盖
保护无效的OnDraw(帆布油画){
super.onDraw(画布);
INT CX = this.getMeasuredWidth()/ 2;
INT CY = this.getMeasuredHeight()/ 2;
canvas.scale(1F,-1f,CX,CY);
canvas.drawText(凌晨3点,CX,CY,P);
}
完整的例子:
公共类SView扩展视图{
涂料P,漆;
公共SView(上下文的背景下){
超(上下文);
// TODO自动生成构造函数存根
P =新的油漆();
p.setColor(Color.RED);
p.setTextSize(40);
油漆=新的油漆();
paint.setColor(Color.BLUE);
paint.setTextSize(40);
}
@覆盖
保护无效的OnDraw(帆布油画){
super.onDraw(画布);
INT CX = this.getMeasuredWidth()/ 2;
INT CY = this.getMeasuredHeight()/ 2;
canvas.drawText(凌晨3点,CX,CY,油漆);
canvas.save();
canvas.scale(1F,-1f,CX,CY);
canvas.drawText(凌晨3点,CX,CY,P);
canvas.restore();
}
}
快
How do you rotate text that is in the canvas? I need to flip the text I have upside down.
paint.setTextSize(20);
canvas.drawText("3AM", xStored, yStored, paint);
解决方案
I got the solution from the comment by Romain Guy below the accepted answer
How can you display upside down text with a textview in Android?
Quoting You can just scale by -1 on the Y axis.
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int cx = this.getMeasuredWidth() / 2;
int cy = this.getMeasuredHeight() / 2;
canvas.scale(1f, -1f, cx, cy);
canvas.drawText("3AM", cx, cy, p);
}
Complete Example:
public class SView extends View {
Paint p,paint;
public SView(Context context) {
super(context);
// TODO Auto-generated constructor stub
p = new Paint();
p.setColor(Color.RED);
p.setTextSize(40);
paint = new Paint();
paint.setColor(Color.BLUE);
paint.setTextSize(40);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int cx = this.getMeasuredWidth() / 2;
int cy = this.getMeasuredHeight() / 2;
canvas.drawText("3AM", cx, cy, paint);
canvas.save();
canvas.scale(1f, -1f, cx, cy);
canvas.drawText("3AM", cx, cy, p);
canvas.restore();
}
}
Snap
这篇关于旋转文本在画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文