简体   繁体   English

画布-多种合成操作

[英]Canvas - Multiple Compositing Operations

Is it possible to use multiple compositing for different "things" when they're being drawn? 在绘制不同的“事物”时是否可以对它们进行多次合成?

For instance I want to use lighter for specific kinds of fillRect's, but for the rest i want to keep everything as usual. 例如,我想对特定种类的fillRect使用打火机,但对于其余部分,我想保持一切正常。

Sure, composition mode can be changed on the fly before each drawing so you can change to "lighter" for some draw operations, "source-over" for others. 当然,可以在每次绘制之前即时更改构图模式,因此对于某些绘制操作,可以将其更改为“较浅”,对于其他绘制操作,可以将其更改为“ source-over”。

Just be aware of that some comp modes may clear what is already drawn so choose wisely. 请注意,有些补偿模式可能会清除已绘制的内容,因此请明智地选择。

ctx.globalCompositeOperation = "lighter";      // lighter mode (blend mode)
ctx.fillRect(x, y, w, h);

ctx.globalCompositeOperation = "source-over";  // normal mode (comp mode)
ctx.fillRect(x, y, w, h);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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