how to make full circular image view in android [d

2019-01-31 19:29发布

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.

2条回答
Melony?
2楼-- · 2019-01-31 19:49

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));
查看更多
时光不老,我们不散
3楼-- · 2019-01-31 19:54

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);
查看更多
登录 后发表回答