how to make full circular image view in android [duplicate]

天涯浪子 提交于 2019-11-29 22:31:02

Get the Bitmap:

Bitmap bitmap = getthebitmapyouwanttoshowinacirclefromsomewhere;
Bitmap circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);

Use a shader:

BitmapShader shader = new BitmapShader (bitmap,  TileMode.CLAMP, TileMode.CLAMP);
Paint paint = new Paint();
        paint.setShader(shader);

Draw the canvas;

Canvas c = new Canvas(circleBitmap);
c.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, paint);

Set the image:

myImageView.setImageBitmap(circleBitmap);

Create A bitmap then draw on its canvas and then add this bitmap to an imageview or button or whatever you want.

Create A bitmap:

Bitmap bmp = Bitmap.createBitmap(width, height, config);

Draw on the bitmap canvas

Canvas c = new Canvas(bmp);
c.drawCircle(cx, cy, radius, paint)

setting to imageview

img.setBackgroundDrawable(new BitmapDrawable(bmp));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!