我需要绘制一张透明度乘以颜色的图片。我找到的唯一方法是像这样在离屏画布中准备一个乘以颜色的图片:
ctx.globalCompositeOperation = "copy"; // copy pixel-to-pixel source image
ctx.drawImage(image, ...);
ctx.globalCompositeOperation = "multiply"; // multiply it by red color
ctx.fillStyle = "#FF0000";
ctx.fillRect(...);
ctx.globalCompositeOperation = "destination-atop"; // restore transparency
ctx.drawImage(image, ...);
然后将其绘制到必要的画布上。
有更好(更快)的方法来做同样的事情吗?