gpt4 book ai didi

java - canvas.drawBitmap( bitmap, null, RectF, null ) 不绘制

转载 作者:太空宇宙 更新时间:2023-11-04 15:19:41 24 4
gpt4 key购买 nike

我正在尝试在我的 android 项目中的 Canvas 上绘制位图图像。我已经研究了两天多了,但似乎无法弄清楚。我附上了调用该函数的代码。

private void drawLogo(Canvas canvas)
{
Paint test = new Paint();
test.setColor(Color.RED);
test.setStrokeWidth(4);
test.setStyle(Style.FILL_AND_STROKE);

//Here was my problem
//Changed to --> new RectF(scale_x, scale_y, 5*scale_x, 5*scale_y) and works now
RectF logoSize = new RectF(scale_x, 5*scale_y, 5*scale_x, scale_y);

Bitmap logoBitmap = getImageMap().get("LOGO");

canvas.drawRect(logoSize, test);

canvas.drawBitmap( logoBitmap, null, logoSize, null );
}

canvas.drawRect( RectF, Paint ) 方法正确绘制了矩形,但位图根本不显示。任何见解将不胜感激,提前致谢。

编辑:我根据要求从 getImageMap() 方法添加了代码。它基本上只是将我的 asset/images/文件夹中的所有图像作为 map 返回,因此我可以轻松地从文件夹中提取我想要的任何图像。

private Map<String, Bitmap> getImageMap()
{
if (imageMap == null)
{
imageMap = new HashMap<String, Bitmap>();
try
{
String[] files = getContext().getAssets().list("images");

for (String imageName : files)
{
// Construct a BitMap from an asset
Bitmap bitmap = BitmapFactory.decodeStream(
getContext().getAssets().open("images/" + imageName));
imageMap.put(imageName.replaceFirst("\\..*", ""), bitmap);
}
}
catch (IOException e) {Log.e("assets/images/ is empty", "IOException", e);}
}
return imageMap;
}

EDIT2:我发现了我的错误,我在代码中更新了它。我只是想感谢那些给我快速反馈的人,我很感激。

最佳答案

尝试一些简单的事情:

canvas.drawBitmap(logoBitmap, logoSize.left, logoSize.top, null);

问候。

关于java - canvas.drawBitmap( bitmap, null, RectF, null ) 不绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20534261/

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