Last Updated: February 25, 2016
·
5.324K
· nadavfima

Show Circle Image in Android

Here I will show you how to draw a bitmap within a circle, instead of a block.
Just override your onDraw method and use this sample:

// init shader
BitmapShader shader;
shader = new BitmapShader(originalBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);

// init paint
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);

int circleCenter = width / 2;

// circleCenter is the x or y of the view's center
// radius is the radius in pixels of the cirle to be drawn
// paint contains the shader that will texture the shape

canvas.drawCircle(circleCenter, circleCenter, radus, paint);

Source (my blog): http://nadavfima.com/circle-image/