Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a png which is mostly transparent, except for a shape I've drawn in white. I want to be able to blend this bitmap with a color when drawing it with Canvas. I'd like something like [Sa, (Dc * (1 - Sa)) + (Sc * C * Sa)], where C would be the color I want to blend with. I assumed I would just set the paint color to C, then call drawBitmap, but the default behavior doesn't seem to be blending.

Is this the right approach? Are there some Xfer codes I'm missing? Can I create a custom shader to do this? Is there an example in the android sdk api I missed that does this?

As an additional constraint, I should mention I want to avoid just creating a new bitmap with the blended color to use. The color C (above) could change every frame, and I don't want to have to generate 100's of these bitmaps for every color that I might need.

share|improve this question

1 Answer 1

up vote 8 down vote accepted
Paint p = new Paint(Color.RED);
ColorFilter filter = new LightingColorFilter(Color.RED, 1);
p.setColorFilter(filter);

Then draw with that Paint object.

Found at "How do you tint a bitmap in Android?"

share|improve this answer
    
Thanks! Let me try this and get back to you. Don't think I ever would have found that answer you linked, never referred to it as tinting while doing directX stuff. –  Jeremiah Nunn Nov 10 '10 at 3:41
    
Awesome, thanks! –  Jeremiah Nunn Nov 10 '10 at 6:04
    
Also, I accepted this as the answer. I'd upvote but I don't have the rep yet. –  Jeremiah Nunn Nov 10 '10 at 6:05
    
Any particular reason to add "1" to the color value? Also, when they say "multiply", I assume they are multiplying by (channelValue / 255). Is that right? –  snapfractalpop Jun 6 at 15:35
    
Seeing as this answer is four years old, I have no idea. Sorry. I would experiment with it to find out what happens when you change the 1 to a 0 or other values. From looking at documentation and the values of the different Colors, I suspect 0 would be just as effective and more correct for the second parameter. But just a guess. –  Ricket Jun 10 at 23:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.