1

I have set a rounded image view Rounded image view and i don't know how to set a background color for it .I had tried set background method to fill the color in the image.

public Bitmap roundCornerImage(Bitmap raw, float round) {
    int width = raw.getWidth();
    int height = raw.getHeight();
    Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(result);
    canvas.drawARGB(0, 0, 0, 0);
    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.parseColor("#000000"));
    final Rect rect = new Rect(0, 0, width, height);
    final RectF rectF = new RectF(rect);
    canvas.drawRoundRect(rectF, round, round, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(raw, rect, rect, paint);
    return result;
}
Community
  • 1
  • 1
Ko Vartthan
  • 434
  • 1
  • 4
  • 22

3 Answers3

2
canvas.drawARGB(0, 0, 0, 0)

This line will draw a canvas of black color. If you just want to change the color, change the rgb values. For e.g

canvas.drawARGB(255, 0, 0, 0)

will draw a red color bitmap canvas.

Aman Grover
  • 1,621
  • 1
  • 21
  • 41
-1
ImageView imageView = (ImageView) findViewById(imageViewId);

// Set the background for the ImageView
imageView.setBackgroundResource(R.drawable.yourdrawableImage);

// set background color
backgroundImg.setBackgroundColor(Color.parseColor("#FFFFFF"));
shalini
  • 355
  • 4
  • 17
-1
setBackgroundColor(Color.rgb(100, 100, 50));

Or else change the background color of parent layout.

Sachin Saxena
  • 604
  • 5
  • 10