在使用自由绘制模式时,我想向画布添加具有不透明度的不同线条。这些线条在相互绘制时不应该累加它们的不透明度。因此,我将画布混合模式更改为
xor
。但是,在彼此覆盖绘制线条时,不透明度仍会相加。我在这里做错了什么?
var canvas = new fabric.Canvas("a", {
isDrawingMode : true
});
document.getElementById("cbFreeDrawing").onchange = function () {
canvas.isDrawingMode = this.checked;
};
canvas.setBackgroundImage('http://fabricjs.com/assets/jail_cell_bars.png', canvas.renderAll.bind(canvas));
canvas.freeDrawingBrush.width = 25;
canvas.freeDrawingBrush.color = "rgba(255,0,0,.5)";
//this seems not to work
canvas.getContext().globalCompositeOperation = 'xor';
canvas {
border: 1px solid;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.6.3/fabric.min.js"></script>
Drawing Mode: <input id="cbFreeDrawing" type="checkbox" checked="true"/><br/>
<canvas id="a" width="400" height="300"></canvas>