1
我在圖案圖像的畫布上畫了多邊形對象。使用Fabric.js可以用圖案填充多邊形嗎?
fabric.Image.fromURL("http://netdna.webdesignerdepot.com/uploads/album_artwork/t2-7.jpg", function(img) {
img.scaleToWidth(100).set({
originX: 'left',
originY: 'top'
});
var patternSourceCanvas = new fabric.StaticCanvas();
patternSourceCanvas.add(img);
var pattern = new fabric.Pattern({
source: function() {
patternSourceCanvas.setDimensions({
width: img.getWidth() + 0,
height: img.getHeight() + 0
});
return patternSourceCanvas.getElement();
},
repeat: 'repeat'
});
canvas.add(new fabric.Polygon([
{x: 185, y: 0},
{x: 250, y: 100},
{x: 385, y: 170},
{x: 0, y: 245} ], {
left: 220,
top: 200,
angle: -30,
fill: pattern
}));
});
我在這裏找到了這個資源。
http://fabricjs.com/dynamic-patterns/
但我要填補多邊形對象SVG文件類型。
是否有可能?
謝謝...