
卡拉OK视频制作
卡拉OK视频制作,在几分钟内制作出你的卡拉OK视频
178 查看详情
在本教程中,我们将学习如何使用 FabricJS拉直图像对象。我们可以通过创建fabric.Image的实例来创建一个Image对象。既然是一个FabricJS 的基本元素,我们还可以通过应用轻松自定义它诸如角度、不透明度等属性。为了拉直图像对象,我们使用拉直方法。
语法
straighten(): fabric.Object
在不使用straighten的情况下向角度属性传递值方法
示例
让我们看一个代码示例,看看当 straighten 时我们的 Image 对象看起来如何方法没有被使用。 straighten 方法通过将对象从其所在位置旋转来straighten当前角度为 0、90、180 或 270 等,具体取决于更接近的角度。角度属性设置对象的旋转角度(以度为单位)。在这里,我们指定了角度为 45。但是由于我们没有应用 straighten 属性,所以旋转角度将保持 45 度。
Passing the angle property a value without using the straighten method
You can see that the Image object has an angle of 45 degrees
// Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); // Initiating the image element var imageElement = document.getElementById("img1"); // Initiate an Image object var image = new fabric.Image(imageElement, { top: 50, left: 110, angle: 45, }); // Add it to the canvas canvas.add(image);
Using the straighten 方法
示例
让我们看一个代码示例,看看当 straighten 时 Image 对象是什么样子的方法与角度属性结合使用。虽然我们已经设定了角度旋转为 45 度,我们的图像对象将通过将其旋转回 0 来拉直degree as we have used the 拉直方法。
Using the straighten method
You can see that the angle of rotation is 0 degree for the image object
// Initiate a canvas instance var canvas = new fabric.Canvas("canvas"); canvas.setWidth(document.body.scrollWidth); canvas.setHeight(250); // Initiating the image element var imageElement = document.getElementById("img1"); // Initiate an Image object var image = new fabric.Image(imageElement, { top: 50, left: 110, angle: 45, }); // Add it to the canvas canvas.add(image); // Using the straighten method image.straighten();
以上就是如何使用 FabricJS 拉直 Image 对象?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/529175.html
微信扫一扫
支付宝扫一扫