How to hone Android bitmap in white?

I want to colorize a bitmap in different colors. Thanks to this SE question, I can push it in different colors when I paint it on my canvas.

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

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

+4
source share
1 answer

Ok I am responsible for people who may run into this problem.

To preserve the shape of the bitmap and colorize it, you need to use i PorterDuffColorFilterinstead of the one used LightingColorFilter.

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

- PorterDuff.Mode,

+8

Source: https://habr.com/ru/post/1542525/


All Articles