Javascript 画布-多个合成操作

Javascript 画布-多个合成操作,javascript,html,canvas,html5-canvas,Javascript,Html,Canvas,Html5 Canvas,在绘制不同的“对象”时,是否可以对其使用多个合成 例如,我想对特定类型的fillRect使用打火机,但对于其他类型的fillRect,我希望一切都像往常一样。当然,可以在每次绘图之前动态更改合成模式,因此对于某些绘图操作,可以更改为“打火机”,对于其他绘图操作,可以更改为“源代码切换” 只是要知道,一些comp模式可能会清除已经绘制的内容,所以要明智地选择 ctx.globalCompositeOperation = "lighter"; // lighter mode (blend

在绘制不同的“对象”时,是否可以对其使用多个合成


例如,我想对特定类型的fillRect使用打火机,但对于其他类型的fillRect,我希望一切都像往常一样。

当然,可以在每次绘图之前动态更改合成模式,因此对于某些绘图操作,可以更改为“打火机”,对于其他绘图操作,可以更改为“源代码切换”

只是要知道,一些comp模式可能会清除已经绘制的内容,所以要明智地选择

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);