對於Andriod的我有這樣的代碼:繪製位圖,而不是矩形
public Tank(int color) {
bounds = new RectF();
paint = new Paint();
paint.setColor(color);
}
public void draw(Canvas canvas) {
bounds.set(x - radius, y - radius, x + radius, y + radius);
canvas.drawRect(bounds, paint);
}
我在哪裏畫一個矩形,但現在我要畫一個位圖,而不是一個矩形,但
bitTank = BitmapFactory.decodeRescource(getRescource(),R.drawable.ic_launcher);
或
bitTank = BitmapFactory.decodeFile("C:\Users\...\res\drawable-hdpi\ic_launcher.png");
(兩者)結合
canvas.drawBitmap(bitTank, matrix, null);
不起作用。第一個不知道getRescource()
,第二個不再工作。我怎麼能意識到這一點? (代碼在坦克類中,另一個類調用繪圖函數)。
感謝您的編輯,當我試圖格式化它時,它不工作... – user1053864 2012-04-02 13:31:46