Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tint an Android bitmap in White?

Tags:

android

bitmap

I want to colorize a bitmap into different colors. Thanks to this SE question i am able to tint my it into different colors when i draw it on my canvas.

Paint p = new Paint(Color.RED);
ColorFilter filter = new LightingColorFilter(Color.RED, 1);
p.setColorFilter(filter);

But this seems to not work with Color.WHITE (maybe because my bitmap is colorized in only 1 color). I want to have a white shape of the original bitmap (only transparent + white)

like image 773
Arnaud Avatar asked Feb 12 '23 20:02

Arnaud


1 Answers

Ok. I reply here for people who might face this problem.

In order to keep the shape of a bitmap, and colorize it you need to use a PorterDuffColorFilter instead of the LightingColorFilter i used initially.

 filter = new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
 mPaint.setColorFilter(filter);

The second parameter is a PorterDuff.Mode, you can find the complete list here

like image 145
Arnaud Avatar answered Feb 15 '23 11:02

Arnaud