简体   繁体   中英

Clear from CALayer mask?

I have a base layer, masked with a transparent mask layer.

Mask layer have a sublayer, a transparent circle. Works fine, the base layer is masked with the circle.

But I want to clear (zero out) the mask pixels with the circle. Not fill up with. Can you get what I want?

How?


在此处输入图片说明

You can see the alpha channels of the mask images here.


It is a 60 fps animation, so allocating instances/custom drawing every frame I think is not a solution, that would cut down performance.

It can be carried out via custom drawing only , in a CALAyer subclass (at least on iOS, having no any CIFilter for blending yet). Exactly what I wanted to avoid. :(

There are many ways, but the simplest seems to use the clear blend mode.

// Draw with Clear (!) blend mode.
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextSetFillColorWithColor(context, self.color.CGColor);
CGContextFillPath(context);

Don't even need any clipping or masking. Maybe I'll gain performance by cache the path renderings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM