如何将我的位图从drawCircle更改为drawable中的导入图像?

我有以下代码:

canvas.drawCircle((currentX * totalCellWidth)+(cellWidth/2),
    (currentY * totalCellHeight)+(cellWidth/2),
    (cellWidth*0.45f),ball);


...产生以下输出:



我尝试了此更改以将位图资源替换为圆圈:

Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

canvas.drawBitmap(b, (currentX * totalCellWidth)+(cellWidth/2),
        (currentY * totalCellHeight)+(cellWidth/2),
        ball);


...但是似乎无效。

最佳答案

如果您尝试更改位图的大小。

Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

// assign value for the new target size
int newsizeX = width;
int newsizeY = height;

resizedbitmap = Bitmap.createScaledBitmap(resizedbitmap, width, height, true);

canvas.drawBitmap(resizedbitmap, *location in X*, *location in Y*, paint);


它应该工作正常:)

07-24 12:50