Transparent brushes


#1

Hello,

I’m trying to tile an image with an alpha channel over a background image. The image is mostly transparent, as it contains only the shadow details of a button shape. I thought it would be convenient to use an ImageBrush rather than repeatedly calling drawImage. My problem is that I don’t understand the contribution of the current color (which set to transparent black).

When I use drawImage with the same source image, I get the expected result, but if I do fillAll or fillPath using an ImageBrush created from the image, this results in what appears to be transparent white filling the brushed area, and my image on top of that.

Here’s a code snippet (this is in an override of LookAndFeel::drawButtonBackground):

ImageBrush br(&tile,0,0,1.0f); g.setColour(Colour(0xff000000)); g.setBrush(&br); g.fillAll();

Confusingly, if I call setColour after setBrush, I get an entirely black rectangle! Is this expected behavior?

Thanks in advance for any insights.

–scott


#2

The colour and the brush are completely separate - if you set a colour, it’ll paint with that solid colour, and if you set a brush, it’ll use that brush, not the colour. The example you give won’t do anything involving transparent white, so can’t really see what you mean…?


#3

Thanks for the reply, Jules. I realized that the problem was due to an error in my code that copies the tileable portion from a source Image. I neglected to clear the destination Image, and therefore the source alpha values were lost.