7
我想繪製一條路徑,並將它用作我的畫布的遮罩。剪輯到繪製路徑
'use strict';
var canvas = new fabric.Canvas('c', {
hoverCursor: 'pointer',
isDrawingMode: true
});
canvas.freeDrawingBrush = new fabric.PencilBrush(canvas);
canvas.freeDrawingBrush.color = '#000';
canvas.freeDrawingBrush.width = 100;
fabric.Image.fromURL('http://fabricjs.com/assets/pug_small.jpg', function(img) {
canvas.add(img);
canvas.setWidth(img.getWidth());
canvas.setHeight(img.getHeight());
canvas.centerObject(img);
img.selectable = false;
});
canvas.on('path:created', function(data) {
var path = data.path;
canvas.remove(path);
canvas.clipTo = function(context) {
path.render(context);
};
canvas.isDrawingMode = false;
canvas.renderAll();
});
如何讓整個路徑成爲圖像的可見區域?
編輯
這就是我想實現的,但使用FabricJS。
http://www.createjs.com/demos/easeljs/alphamaskreveal
你想只使用路徑,而不是區域的路徑內,作爲面膜?確切地說, – approxiblue
。例如,對於SprayBrush,我只想將紅色部分用作掩碼http://jsfiddle.net/db45yhpo/2/ –