gpt4 book ai didi

android - 如何显示位图资源与使用形状绘制命令?

转载 作者:行者123 更新时间:2023-11-30 02:48:42 25 4
gpt4 key购买 nike

如何将我的位图从 drawCircle 更改为可绘制的导入图像?

我有这个代码:

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

...产生此输出:

enter image description here

我尝试通过此更改来替换圆的位图资源:

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);

它应该工作得很好:)

关于android - 如何显示位图资源与使用形状绘制命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24587252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com