在画布上以角度绘制文本

11

如何在画布上绘制文本,就像下图中突出显示的绿色矩形一样。

enter image description here

我已经编写了以下代码……但是从这个代码中,我只能以直线的方式编写文本。无法以角度编写文本。

Bitmap bmpLayered = Bitmap.createBitmap(bmpMain.getWidth(), bmpMain
                .getHeight(), Bitmap.Config.ARGB_8888);
        Canvas cv = new Canvas(bmpLayered);

Paint charPaint = new Paint();
        charPaint.setAntiAlias(true);
        charPaint.setStyle(Paint.Style.FILL);
        charPaint.setTextSize(24);
        charPaint.setColor(Color.BLACK);
        charPaint.setStrokeWidth(3);

cv.drawText("None", 570, 222, charPaint);

请帮我解决这个问题。

谢谢。

2个回答

31
cv.save();
cv.rotate(-45, x, y);
cv.drawText("your text here", x, y, paint);
cv.restore();

其中 cv 是指您的画布的引用,x 和 y 是您想绘制的点。


1

在将文本绘制到画布上后,您可以旋转画布。

cv.drawText("None", 570, 222, charPaint);
//rotate the canvas
cv.rotate(45f);
// or around a pivot point
cv.rotate(45f, 100, 100);

Android开发者:图形-画布旋转


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接