0

I want to add a circle black shape to the circle ImageView I have.

I want something like this :

enter image description here

here is my code to make the ImageView circle :

 private Bitmap getCircleBitmap(Bitmap bitmap) {
    final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(output);

    final int color = Color.RED;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final RectF rectF = new RectF(rect);

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawOval(rectF, paint);

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);

    bitmap.recycle();

    return output;
}
Stranger B.
  • 9,004
  • 21
  • 71
  • 108

2 Answers2

1

you can use CircleImageView:

https://github.com/hdodenhof/CircleImageView

compile 'de.hdodenhof:circleimageview:2.0.0'
Milad Nouri
  • 1,587
  • 1
  • 21
  • 32
0

If you want to make your images rounded, then use RoundedImageView as explained in this answer.

Community
  • 1
  • 1
Moïze
  • 707
  • 8
  • 16