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
add comment

1 Answer

up vote 6 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
add comment

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.