context.globalCompositeOperation = 'destination-in';
context.fillRect(200, 220, 200, 100); //Or something similar
destination-in
つまり、 MDCごとに:既存のキャンバスコンテンツは、新しい形状と既存のキャンバスコンテンツの両方が重なる場所に保持されます。他のすべては透明になります。
または逆に
context.fillRect(200, 220, 200, 100);
context.globalCompositeOperation = 'source-in';
//Draw arc...
source-in
つまり、新しいシェイプは、新しいシェイプとデスティネーションキャンバスの両方が重なる場所にのみ描画されます。他のすべては透明になります
これらの方法は両方とも、すでにキャンバスに描画されている他のコンテンツを混乱させることになります。これが問題である場合は、clip
context.save();
context.beginPath();
//Draw rectangular path
context.moveTo(200, 220);
context.lineTo(400, 220);
context.lineTo(400, 320);
context.lineTo(200, 320);
context.lineTo(200, 220);
//Use current path as clipping region
context.clip();
//Draw arc...
//Restore original clipping region, likely the full canvas area
context.restore()