Reputation: 491
Currently I'm using this code..
public static Bitmap getCircularBitmap(Bitmap bitmap, int borderWidth) {
if (bitmap == null || bitmap.isRecycled()) {
return null;
}
int width = bitmap.getWidth() + borderWidth;
int height = bitmap.getHeight() + borderWidth;
Bitmap canvasBitmap = Bitmap.createBitmap(width, height,Bitmap.Config.ARGB_8888);
BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
Canvas canvas = new Canvas(canvasBitmap);
float radius = width > height ? ((float) height) / 2f: ((float) width) / 2f;
canvas.drawCircle(width / 2, height / 2, radius, paint);
paint.setShader(null);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.WHITE);
paint.setStrokeWidth(borderWidth);
canvas.drawCircle(width / 2, height / 2, radius - borderWidth / 2, paint);
return canvasBitmap;
}
Its returns a circular bitmap, but size of images getting different according to real image size.
A sample Image of app..
first profile image is smaller then second.
Please help me out.. Thanks.
Upvotes: 2
Views: 1019