Canvas - 多重合成操作
Canvas - Multiple Compositing Operations
是否可以在绘制不同 "things" 时使用多重合成?
例如,我想对特定种类的 fillRect 使用打火机,但对于其余部分,我想保持一切照常。
当然,可以在每次绘制之前即时更改合成模式,因此您可以将某些绘制操作更改为 "lighter",对其他绘制操作更改为 "source-over"。
请注意,某些合成模式可能会清除已绘制的内容,因此请明智地选择。
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);
是否可以在绘制不同 "things" 时使用多重合成?
例如,我想对特定种类的 fillRect 使用打火机,但对于其余部分,我想保持一切照常。
当然,可以在每次绘制之前即时更改合成模式,因此您可以将某些绘制操作更改为 "lighter",对其他绘制操作更改为 "source-over"。
请注意,某些合成模式可能会清除已绘制的内容,因此请明智地选择。
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);