How to draw on bitmap using another bitmap as mask?
Asked Answered
L

2

6

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

Lundt answered 24/7, 2013 at 13:28 Comment(3)
do you have any choice/possibility to change the masks? e.g. using white object on transparent background? then you could use some kind of multiply between mask and blue colorImhoff
in either case, this guide could help you to do what you'd like kevindion.com/2011/01/android-bitmap-blending-color-channelsImhoff
Yes, I believe I could change the masks. The link provided is great! Thanks!Lundt
L
9

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);
Lundt answered 24/7, 2013 at 16:37 Comment(0)
L
0

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!

Lepley answered 24/7, 2013 at 17:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.