Recolouring an image


If I’ve got a PNG in transparent and black and I’d like to change the black so it renders in some other colour is there a convenient way of doing it?


In the drawImage call you can pass “fillAlphaChannelWithCurrentBrush”. So if you set that variable to “true” and put a “setColour (Colours::red)” before the drawImage call, all pixels get replaced with red-pixels. You can use a different alpha to blend the original image with your colour too. e.g.

setColour (Colours::red.withAlpha (0.5f));
drawImageAt (image, 0, 0, true);

Would draw you image with 50% red and 50% your pixel colours. It respects the alpha of each pixel, so for 100% transparent pixels, they will stay transparent etc.



You can also pass a semi-transparent image into Graphics::reduceClipRegion so that it creates a masked area, and then you can paint whatever fill patterns you like into it.


Thank you both!