Reputation: 1499
I would like to draw bitmap(with specified color) on canvas.
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
// create bitmap
canvas.drawBitmap(bitmap, 0, 0, paint);
Well, the bitmap is visible on the canvas, but color of drawable didn't change. Where is the problem?
Upvotes: 2
Views: 1164
Reputation: 1726
paint.setColor(Color.RED)
is irrelevant. If your image comes with an alpha channel and you want it to be drawn in a single color, use ColorFilter
instead:
paint.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
Upvotes: 2
Reputation: 59168
I would like to draw bitmap(with specified color) on canvas.
A bitmap contains an image and drawing an image in single color doesn't make any sense. What do you expect it to do? Draw a red rectangle? Shapes can be drawn with color, not images...
The Color
attribute of your Paint
will be ignored. That Paint
parameter is used to pass other settings such as anti-aliasing.
I hope this clarifies.
Upvotes: 4