Canvas で「消しゴム」効果を作成しようとしていますが、消しゴムのカスタム形状として SVG 画像を使用しています。
したがって、SVG 画像をキャンバスに描画し、globalCompositeOperation='destination-out' を使用してマスキング効果を作成できます。
IE、Safari、および Chrome でうまく機能します。しかし、Firefox では完全に失敗します。
function init() {
var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');
var img = document.createElement('IMG');
img.onload = function () {
ctx.beginPath();
ctx.drawImage(img, 0, 0);
ctx.closePath();
ctx.globalCompositeOperation = 'destination-out';
}
img.src = "http://www.evanburke.com/FROST.png";
var svg = new Image;
svg.src = "http://www.evanburke.com/luf.svg";
function drawPoint(pointX,pointY){
ctx.drawImage(svg,pointX,pointY);
}
canvas.addEventListener('mousemove',function(e){
drawPoint(e.clientX,e.clientY);
},false);
}
<body onload="javascript:init();">
<div>
<canvas id="c" width="400" height="400"></canvas>
</div>
</body>