使用目標輸出刪除現有形狀

context.globalCompositeOperation = "destination-out"

目的地合成使用新形狀來擦除現有圖紙。

實際上並沒有繪製新形狀 - 它只是用作切割器來擦除現有畫素。

context.drawImage(apple,0,0);
context.globalCompositeOperation = 'destination-out';   // bitemark erases
context.drawImage(bitemark,100,40);

StackOverflow 文件