2012-12-20 94 views
0

我一直被這一點難住了一點,所以我想我會問在這裏看看是否有人有任何指針。在Android上的畫布上繪製自定義形狀

簡而言之,我有一個應用程序,我想要在畫布上繪製多個複雜的形狀,然後將其繪製到屏幕上(我將按照此問題答案中的建議在大畫布上實施平移:Android: Drawing and rotating on a canvas

我到底該如何創建一個自定義形狀,並在Android的Canvas上的任意位置/旋轉中繪製它?

下面是一個簡單的自定義形狀的例子,因爲我已經嘗試實現它至今(通常他們會在運行時創建的)

public class Symbol { 
    public Bitmap b = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888); 
    public Symbol() { 
     Canvas canvas = new Canvas(b);; 
     Paint paint = new Paint(); 
     paint.setColor(Color.GRAY); 
     paint.setStyle(Paint.Style.STROKE); 
     paint.setTextSize(25); 
     paint.setStrokeWidth(4); 
     paint.setDither(true);      
     paint.setStrokeJoin(Paint.Join.ROUND);  
     paint.setStrokeCap(Paint.Cap.ROUND);  
     paint.setAntiAlias(true); 
     String str="TestStr"; 
     canvas.drawText(str, 250,250, paint); 
    } 
} 

回答

0

哇,我derped這個鐵桿一。

Android: canvas.drawBitmap performance issue

在我的主類所做的一切快樂添加此,至少就這個簡單的例子去:

Symbol s = new Symbol(); 
canvas.save(); 
canvas.rotate(5); 
canvas.drawBitmap(s.b, 0,0, null); 
canvas.restore(); 
+0

另外,看「圖片」:HTTP://開發商。 android.com/reference/android/graphics/Picture.html –