Alpha masks with CanvasKit?

11 views
Skip to first unread message

Devin Abbott

unread,
Jun 3, 2021, 4:02:57 PM (9 days ago) Jun 3
to skia-discuss
Hi folks, I'm currently creating an open source UI design app (think Sketch/Figma), and I'm trying to implement "alpha masks". What would be the best way to do this with CanvasKit?

Here's an example of how it should work:
AlphaMaskExample.png
The alpha of each pixel of the "mask" should be assigned to the corresponding pixel of the "contents" to get the "masked contents". The r/g/b of the mask is discarded. 

I'm currently calling `saveLayer` before drawing the contents. Is there a way to apply a filter containing the mask data to get this effect? This feels like a blending mode, but I'm not really sure. I'm using the canvaskit-wasm package from npm at the moment, but if it would simplify things to expose a different ImageFilter or something in a custom build, I could do that too.
Reply all
Reply to author
Forward
0 new messages