2012-06-28 47 views
7

如何在畫布上繪製文字,如下圖中突出顯示的圖像Green rectangle在角度上在畫布上繪製文本

enter image description here

我做了下面的代碼....但是從這個代碼,我可以在straight寫入文本。不能在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); 

請幫我解決這個問題。

謝謝。

回答

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

其中cv是參考你的畫布,X & y這裏你想要的點來繪製。

+0

由於它的工作.. – Nikhil

1

將文字繪製到畫布後,可以旋轉畫布。

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

+0

它不工作..dear – Nikhil