gpt4 book ai didi

javascript - 如何在fabric js中将图像添加到组中

转载 作者:行者123 更新时间:2023-11-30 00:18:42 25 4
gpt4 key购买 nike

enter image description here在选择对象时在 fabric js 中,我想在该组上添加十字图标图像。请帮助如何实现。

             <script>        
canvas.on('object:selected', function (e) {
var activeobject = e.target; //active element is group in which i want to add image
var imgs = fabric.Image.fromURL('images/delete.png', function (oImg) {

oImg.scale(0.5).setFlipX(true);

});
activeobject.push(imgs);//here .push is giving errpr that it is not a function

});

最佳答案

您可以使用以下代码将图像永久放置在一个矩形中:

 fabric.Image.fromURL('UrlImage', (img) => {

var img1 = img.set({
left: rect.left,
top: rect.top,
width: 100,
height: 100,
});

var group = new fabric.Group([rect, img1]);
this.myCanvas.add(group);
group.addWithUpdate();
});

关于javascript - 如何在fabric js中将图像添加到组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33934760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com