如何在android中的同一点绘制位图和圆

时间:2011-07-24 08:41:28

标签: android bitmap

我正在尝试使用以下代码在同一点绘制位图和圆。但是在不同的地方绘制了圆形和位图。

canvas.drawBitmap(reSized, 0, 0, null);  
pcanvas.drawCircle(stDropCurPoint.x, stDropCurPoint.y, 3, mPaint);  
canvas.drawBitmap(bitmap, 0, 0,null);  
canvas.save();  
canvas.drawBitmap(bmp, stDropCurPoint.x, stDropCurPoint.y, null);  
canvas.restore();

我的位图“bmp”的宽度和高度是50 * 50。我想画一个半径为3的圆。  请告诉我如何在同一点绘制圆和位图。  提前致谢。

1 个答案:

答案 0 :(得分:2)

由于位图x和y坐标指的是图像的左上角,您可能希望将其宽度和高度的一半偏移,使其居中于stDropCurPoint。

canvas.drawBitmap(bmp, stDropCurPoint.x - bmp.getWidth()/2, stDropCurPoint.y - bmp.getHeight()/2, null); 
相关问题