How to draw on bitmap using another bitmap as mask

2019-04-08 07:44发布

I want to draw on a bitmap using another bitmap as mask. The mask is a black bitmap with a transparent object in it. I want this transparent part to be filled with an arbitrary color and added to my original image. How can this be done?

enter image description here

+

enter image description here

+ blue color =

enter image description here

2条回答
时光不老,我们不散
2楼-- · 2019-04-08 08:17

I had to change the masks as described by @Christian. Then, the wanted result could easily be produced:

canvas.drawRect(rect, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
canvas.drawBitmap(mask, 0.0f, 0.0f, paint);
查看更多
Luminary・发光体
3楼-- · 2019-04-08 08:20

If you're setting this to an ImageView, a quick way is to set the background to the gradient drawable, and a blue 'T' with a transparent background as the ImageView's source. Not fancy, but fast and simple!

查看更多
登录 后发表回答