How to create a circular ImageView in Android? [duplicate]

How could I create a rounded ImageView in Android?

I have tried the following code, but it’s not working fine.

Code:

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

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

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

imageView.setImageBitmap(circleBitmap);

Image inside the circle:

Enter image description here

How can I do this?

1 Answer
1

Leave a Comment