gpt4 book ai didi

android - 无法在位图上画圆?

转载 作者:搜寻专家 更新时间:2023-11-01 07:39:22 25 4
gpt4 key购买 nike

我可以显示位图,但我正在绘制的圆圈不显示。我不确定我错过了什么。

private void loadImage() {
File f = new File(imagesPath, currImageName);

Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap);

Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLUE);
canvas = new Canvas();
canvas.drawCircle(60, 50, 25, paint);
bitmapDrawable.draw(canvas);

ImageView imageView = (ImageView)findViewById(R.id.imageview);
imageView.setAdjustViewBounds(true);
imageView.setImageDrawable(bitmapDrawable);
}

最佳答案

您的代码不是在位图上绘制,而是将您的位图绘制到 Canvas 中,然后在该 Canvas 的位图上画一个圆。然后将结果丢弃。然后将原始位图(未更改)设置到 ImageView 中。

您需要使用位图创建 Canvas 。然后 draw 方法将在您的位图上绘制。

    Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());

Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLUE);

// create canvas to draw on the bitmap
Canvas canvas = new Canvas(bitmap);
canvas.drawCircle(60, 50, 25, paint);

ImageView imageView = (ImageView)findViewById(R.id.imageview);
imageView.setAdjustViewBounds(true);
imageView.setImageBitmap(bitmap);

关于android - 无法在位图上画圆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6088723/

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