Transparency
Learn how to add transparency to RGB colors in Pycairo.
We'll cover the following
Adding transparency
Pycairo handles transparent colors, using an additional color channel called alpha. It acts almost like a fourth color, similar to red, green, and blue.
We can set a transparent color like this:
Here, ctx
is the context and r
, g
, and b
control the amount of red, green, and blue in the color, and a
controls the transparency.
The alpha value, like the other colors, is a float between 0.0
and 1.0
. A value of 1.0
represents a fully opaque color, and 0.0
represents a fully transparent color (items that are fully transparent aren’t visible at all). Values in between create translucent colors, where we can see the color but we can also see the items behind it, like this:
Get hands-on with 1400+ tech skills courses.