There are multiple images in the canvas how to select one programmatically in fabric js
fabric.Image.fromURL(this.imageSrc, (img) => {
let oImg = img.set({
left: 0,
top: 0,
angle: 0,
}).scale(1);
this.canvas.add(oImg).renderAll();
You can assign an image to a variable like this:
var oImg;
fabric.Image.fromURL(this.imageSrc, (img) => {
oImg = img.set({
left: 0,
top: 0,
angle: 0
});
canvas.add(oImg).renderAll();
});
Since the image object is now stored as oImg
, you can select it like this:
canvas.setActiveObject(oImg);
Or, you can select objects in the canvas based on their index like this:
var obj = canvas.item(0);
canvas.setActiveObject(obj);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.