Draw Text on Canvas at Angle

Nikhil picture Nikhil · Jun 28, 2012 · Viewed 10k times · Source

How can i draw text on canvas as shown in below image highlighted in Green rectangle .

enter image description here

I have done following code.... but from this code i can write text in straight. can't write text at angle.

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.

Answer

Orlymee picture Orlymee · Jun 28, 2012
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.