[英]How to make an image in the canvas fixed, undraggable, and unselectable using fabricjs
I want to get this image fixed in the canvas so that if I add a text or another image, the image/text will not go back. 我想将此图像固定在画布中,以便在添加文本或其他图像时,该图像/文本不会返回。
<script> function GateFoldClick() {
canvas.clear();
fabric.Image.fromURL('images/FourFoldBrochure.jpg', function (myImg) {
canvas.add(myImg);
myImg.center();
});
}
</script>
You could achieve that using setBackgroundImage()
method. 您可以使用
setBackgroundImage()
方法来实现。
ᴅᴇᴍᴏ ᴅᴇᴍᴏ
var canvas = new fabric.Canvas('c'); fabric.Image.fromURL('https://i.imgur.com/Q6aZlme.jpg', function(img) { img.setWidth(200); img.setHeight(200); canvas.setBackgroundImage(img); canvas.renderAll(); });
canvas{border:1px solid #ccc}
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.7.14/fabric.min.js"></script> <canvas id="c" width="200" height="200"></canvas>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.