Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. public static Bitmap getCircularBitmap(Bitmap bitmap, int borderWidth) {
  2. if (bitmap == null || bitmap.isRecycled()) {
  3. return null;
  4. }
  5.  
  6. int width = bitmap.getWidth() + borderWidth;
  7. int height = bitmap.getHeight() + borderWidth;
  8.  
  9. Bitmap canvasBitmap = Bitmap.createBitmap(width, height,Bitmap.Config.ARGB_8888);
  10. BitmapShader shader = new BitmapShader(bitmap, TileMode.CLAMP, TileMode.CLAMP);
  11. Paint paint = new Paint();
  12. paint.setAntiAlias(true);
  13. paint.setShader(shader);
  14.  
  15. Canvas canvas = new Canvas(canvasBitmap);
  16. float radius = width > height ? ((float) height) / 2f: ((float) width) / 2f;
  17. canvas.drawCircle(width / 2, height / 2, radius, paint);
  18. paint.setShader(null);
  19. paint.setStyle(Paint.Style.STROKE);
  20. paint.setColor(Color.WHITE);
  21. paint.setStrokeWidth(borderWidth);
  22. canvas.drawCircle(width / 2, height / 2, radius - borderWidth / 2, paint);
  23. return canvasBitmap;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement