我想知道是否有可能在现有的imageView上画一个圆圈?
我想在我的图像上创建一个圆圈,下面是我的代码:
public void drawCircle(ImageView image, int x, int y)
{
BitmapDrawable drawable = (BitmapDrawable) image.getDrawable();
Bitmap bitmap = drawable.getBitmap();
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.STROKE);
float radius = 20;
canvas.drawCircle(x, y, radius, paint);
image.setImageBitmap(bitmap);
}
但不幸的是,我有以下错误:
android.graphics.drawable.BitmapDrawable.getBitmap()‘:尝试在空对象引用上调用虚拟方法的android.graphics.Bitmap android.graphics.Bitmap
你能告诉我我的密码出了什么问题吗?
谢谢!
发布于 2015-05-21 02:12:53
您可以为此编写XML来设置椭圆形形状,如下所示
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<gradient android:startColor="YOUR_COLOR" android:endColor="YOUR_COLOR"
android:angle="270"/>
</shape>
将其添加到可绘制文件夹中,然后在imageView上将其设置为源或背景。请确保在设置的高度和宽度相同的情况下,在另一个布局顶部中使用此方法。
访问这个也是为了获得更多的想法,How to create an imageView with shape circle and have a border?
https://stackoverflow.com/questions/30370524
复制相似问题