反转或否定图像有差异

使用复合操作在图像上渲染白色矩形

ctx.globalCompositeOperation = 'difference';

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

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

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

StackOverflow 文档