[cairo] How to use a specified color as png transparent color?

Bill Spitzak spitzak at gmail.com
Wed Oct 26 17:43:46 PDT 2011


First off you might want to see if you can create your png files with 
actual transparency, which will allow antialiasing and will otherwise 
work much nicer and easier.

I think the way to do it is to read the png file into your own 4-channel 
buffer, then search that buffer and change all matching colors to 0, and 
(possibly) change the alpha of all non-matching colors to 0xFF. You can 
then tell Cairo to use this buffer as an image source, telling it that 
it is RGBA.

It looks like trying to modify the Cairo image created from reading the 
png may not work, as it will be marked as being a 3-channel image and 
thus the alpha will be ignored (somebody correct me if wrong!)

Carlo wrote:
> Hi. I would  import a png and copy it on a surface with the "target 
> color" used as transparent color.
> I'm working with different set of png, each set has a background color 
> that I don't want to show.
> How can I make this??
> 
> Thank you for help
> Carlo Ferraresi
> -- 
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo


More information about the cairo mailing list