Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw Text on Canvas at Angle

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.

like image 679
Nikhil Avatar asked Jun 28 '12 13:06

Nikhil


2 Answers

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.

like image 77
Orlymee Avatar answered Nov 04 '22 01:11

Orlymee


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

like image 35
Geert Weening Avatar answered Nov 04 '22 02:11

Geert Weening