黑色白色与颜色

通过删除图像中的颜色

ctx.globalCompositeOperation = 'color';

可以使用 alpha 设置控制效果量

// Render the image
ctx.globalCompositeOperation='source-atop';
ctx.drawImage(image, 0, 0);

// set the composite operation
ctx.globalCompositeOperation='color';
ctx.fillStyle = "white";
ctx.globalAlpha = alpha;  // alpha 0 = no effect 1 = full effect
ctx.fillRect(0, 0, image.width, image.height);

StackOverflow 文档