Fabric.js 图片的hasRotatingPoint属性
Fabric.js 是一个用于处理画布的JavaScript库。画布图片是fabric.js的一个类,用于创建图像实例。画布图片意味着图像是可移动的,并可根据需要进行拉伸。图像的 hasRotatingPoint 属性用于启用或禁用控制旋转点,即使其不可见。
方法: 首先导入fabric.js库。导入库之后,在标签中创建一个包含图像的画布块。之后,使用Fabric.JS提供的Canvas和image类初始化一个实例,然后使用 hasRotatingPoint 属性来启用或禁用画布图像的旋转点。最后,在画布上渲染图像。
语法:
fabric.Image(image, {
hasRotatingPoint : Boolean
});
参数: 此函数使用如上所述的两个参数,并进行以下描述:
- 图片: 此参数接受图像元素。
- hasRotatingPoint: 此参数接受一个布尔值,用于启用或禁用画布图像的旋转点。
示例: 此示例使用FabricJS来禁用画布图像的旋转点,如下所示。
<!DOCTYPE html>
<html>
<head>
<!-- Adding the FabricJS library -->
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js">
</script>
</head>
<body>
<h1 style="color: green;">
GeeksforGeeks
</h1>
<b>
Fabric.js | Image hasRotatingPoint Property
</b>
<canvas id="canvas" width="400" height="300"
style="border:2px solid #000000">
</canvas>
<img src =
"https://media.geeksforgeeks.org/wp-content/uploads/20200327230544/g4gicon.png"
width="100" height="100" id="my-image"
style="display: none;">
<br>
<script>
// Create the instance of canvas object
var canvas = new fabric.Canvas("canvas");
// Getting the image
var img= document.getElementById('my-image');
// Creating the image instance
var imgInstance = new fabric.Image(img, {
});
function hasRotatingPoint(){
imgInstance = new fabric.Image(img, {
hasRotatingPoint: false,
borderScaleFactor:5
});
canvas.clear();
// Rendering the image to canvas
canvas.add(imgInstance);
canvas.centerObject(imgInstance);
}
hasRotatingPoint();
</script>
</body>
</html>
输出:
极客教程