2014-08-30 19 views
0

int currentX = maze.getCurrentX(),currentY = maze.getCurrentY(); //繪製球我想使用自定義png代替canvas.drawcircle函數。怎麼辦?

canvas.drawCircle((currentX * totalCellWidth)+(cellWidth/2), //x of center 
       (currentY * totalCellHeight)+(cellWidth/2), //y of center 
       (cellWidth*0.45f),       //radius 
       ball); 

    //draw the finishing point indicator 
    canvas.drawText("F", 
        (mazeFinishX * totalCellWidth)+(cellWidth*0.25f), 
        (mazeFinishY * totalCellHeight)+(cellHeight*0.75f), 
        ball); 
} 
+0

把png放到你的資源文件夾中,並將它設置爲你的視圖上的背景可繪製 – 2014-08-30 18:41:31

回答

0

你必須爲PNG添加到您的drawable文件夾。那麼你可以使用BitmapFactory.decodeResource(resourceId);創建一個Bitmap。位圖可以使用canvas.drawBitmap(Bitmap bmp, Rect source, Rect dest, Paint p)在畫布上繪製。 bmp是要繪製的位圖,顯然,source是應繪製的位圖部分(在您的情況下是整個位圖),dest是繪製位圖的位置,p是繪製位置不需要,所以只需使用null

+0

比你的確非常:) – user3892782 2014-08-31 10:18:23

相關問題