16

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:

Any thoughts.

Community
  • 1
  • 1
Aamir Shah
  • 4,473
  • 8
  • 21
  • 28

1 Answers1

33

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);
Waza_Be
  • 39,407
  • 49
  • 186
  • 260
  • 1
    Almost got it... but i want the radius to be fixed say 30dp (thats simple), also i wants that the image which is displayed (circular) is from the center of the original pic... – Aamir Shah Jan 06 '13 at 07:18
  • You'll want to change the parameters of this method then: `c.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, paint)`; – nmw Jan 06 '13 at 07:29
  • ya i got the image, but its changing its position in the layout, there is lot of padding/ margin coming on left and top... – Aamir Shah Jan 06 '13 at 07:51
  • Indeed, you will have to play with the parameters in the canvas and drawcircle depending on your needs – Waza_Be Jan 06 '13 at 09:41
  • @Waza_be , make it as a paid answer :-) additionally adding : Use square image for circle . – Tushar Pandey Jun 14 '13 at 10:29