pythoncairopycairo

In PyCairo, can you clip a Surface using another Surface's transparency layer?


So I've done a bit of googling and looking at older threads here but I still have no idea how to do it. I've seen some other ways to clip Surfaces with drawn paths like in the context.clip method, but I haven't seen anything like it for two surfaces.

The thing I'd want is some way to draw some surface A to sone surface B in the places determined by some other surface C's alpha layer. I'm pretty new to PyCairo so I'd appreciate the help :)


Solution

  • You are looking for cairo_mask_surface: https://www.cairographics.org/manual/cairo-cairo-t.html#cairo-mask-surface

    I do not know how this is accessible in PyCairo, but I would guess ctx.mask_surface(surf_c).