Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement