image - Fabric .js : How to make an image in the shape of a circle with white borders

标签 image html5-canvas fabricjs

我正在使用 Fabric.js 在 HTML Canvas 上创建一些动画。我需要做这个:

enter image description here

如果我使用图像元素,我无法将其设为圆形并且不放置白色边框。
如果我使用圆形对象,我无法在其中放置图像。

任何想法将不胜感激。 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/

相关文章:

python - 如何区分视差图像的好坏

java - 将图像从 android 串行发送到 java 应用程序时出错 -javax.imageio.IIOException : Bogus Huffman table definition

javascript - 如何处理2D平台游戏中的复杂输入?

javascript - fabric js中的对象对齐

javascript - 返回大小图像放大缩小

c++ - 将大量图像数据(10^9 像素)加载到内存中

android - 从android中的drawable文件夹随机生成图像

javascript - 线条未绘制在 Canvas 上的正确位置

JavaScript 多边形碰撞检测

javascript - 在 FabricJS 中绘制一条波浪线