我正在使用 Fabric.js 在 HTML Canvas 上创建一些动画。我需要做这个:
如果我使用图像元素,我无法将其设为圆形并且不放置白色边框。
如果我使用圆形对象,我无法在其中放置图像。
任何想法将不胜感激。 TIA
最佳答案
尝试使用 clipTo
函数进行类似的操作:
fabric.Image.fromURL(imageURL, function(oImg) {
oImg.scale(1.0).set({
left: 10,
top: 10,
stroke : 'white',
strokeWidth : 100,
clipTo: function (ctx) {
ctx.arc(0, 0, radius, 0, Math.PI * 2, true);
}
});
canvas.add(oImg).setActiveObject(oImg);
canvas.renderAll();
});
fiddle :http://jsfiddle.net/q6Y6k/8/
关于image - Fabric .js : How to make an image in the shape of a circle with white borders,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30217950/