Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Possible Duplicate:
How to make an image fit into a circular frame in android

I want a 360 degree circular shape Image View, I found related solutions on stackoverflow, but they were all yielding rounded corners in image view. But i want full circular image view.

For rounded corners image view links are:

  • Rounded corners in imageView
  • How to make an ImageView with rounded corners?

Any thoughts.

like image 509
Aamir Shah Avatar asked Jan 06 '13 06:01

Aamir Shah


People also ask

How do I make an image circular in Android?

Simply put a circular_crop. png in your drawable folder which is in the shape of your image dimensions (a square in my case) with a white background and a transparent circle in the center. You can use this image if you have want a square imageview.


1 Answers

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);
like image 97
Waza_Be Avatar answered Nov 17 '22 17:11

Waza_Be