Draw Text on Canvas at Angle
10,714
Solution 1
cv.save();
cv.rotate(-45, x, y);
cv.drawText("your text here", x, y, paint);
cv.restore();
where cv being reference to your canvas, x & y the point where you want to draw.
Solution 2
After you've drawn the text to the canvas you could rotate the canvas.
cv.drawText("None", 570, 222, charPaint);
//rotate the canvas
cv.rotate(45f);
// or around a pivot point
cv.rotate(45f, 100, 100);
Android Developer: Graphics-Canvas Rotate
Author by
Nikhil
Achievements: 36th person to earn Research Assistant badge
Updated on June 04, 2022Comments
-
Nikhil about 2 years
How can i draw text on canvas as shown in below image highlighted in
Green rectangle
.I have done following code.... but from this code i can write text in
straight
. can't write text atangle
.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);
Please help me to solve this.
Thanks.