Component alpha applied twice, a bug?


Is it just me or does the alpha setting of a component (via Component::setAlpha) get applied twice when the component has setBufferedToImage (true) ?

First, Component::paintEntireComponent() uses the alpha in the layer transparency:

            g.beginTransparencyLayer (getAlpha()); // first application of alpha
            paintComponentAndChildren (g);

But Component::paintComponent (), which is eventually called by paintComponentAndChildren (), also sets the alpha

        g.setColour (Colours::black.withAlpha (getAlpha())); // second application of alpha
        g.drawImageAt (bufferedImage, 0, 0);

The result is that the alpha gets applied twice. So a Component with alpha = 0.5 will draw at .25 alpha (.5 * .5).


The ignoreAlphaLevel parameter should be true when paintEntireComponent gets called, so I don’t think that’ll happen…? (I’ve not tried stepping through it though, so I might be wrong)


I tested it with setAlpha (.5f) setBufferedToImage (true) and it does draw at .25f. I found this at first just by looking at the code, you can see that it will produce the wrong result.