当前位置:网站首页>Fabric.js 基础笔刷
Fabric.js 基础笔刷
2022-07-02 05:08:00 【德育处主任】
本文简介
点赞 + 关注 + 收藏 = 学会了
<br>
Fabric.js 开启绘画模式后,可以设置画笔的样式。
画笔又分好几种,本文主要介绍 Fabric 基础画笔的用法。
之前写过 《Fabric.js 橡皮擦的用法》 也用到了绘图模式,有兴趣的可以去看看。
<br>
本文使用
Fabric.js 5.2.1
<br>
<br>
常用的配置
首先要开启一下画布的绘画模式,因为普通的框选模式是不支持绘画的。
<br>
起步

<canvas id="c" width="600" height="400" style="border: 1px solid #ccc;"></canvas><!-- 引入 Fabric.js --><script src="https://cdn.bootcdn.net/ajax/libs/fabric.js/521/fabric.js"></script><script> const canvas = new fabric.Canvas('c', { isDrawingMode: true // 开启绘画模式 })</script>将 isDrawingMode 设为 true 即可开启,这一步很重要,只有设置 isDrawingMode 为 true ,本文接下来的操作才有意义。
如果不想在初始化时设置 isDrawingMode ,也可以在后期使用 canvas.isDrawingMode = true 的方式进行设置。
<br>
注意:接下来所有操作都是基于 “起步” 的代码进行的!!!
<br>
设置笔刷宽度

// 省略 “起步” 代码canvas.freeDrawingBrush.width = 20 // 画笔宽度可以通过修改 width 调节笔刷的粗细。
<br>
设置笔刷颜色

// 省略 “起步” 代码canvas.freeDrawingBrush.width = 20 // 画笔宽度canvas.freeDrawingBrush.color = 'pink' // 画笔颜色我将笔刷的宽度设为20,这样比较容易展示效果。
<br>
虚线

// 省略 “起步” 代码canvas.freeDrawingBrush.width = 20 // 画笔宽度canvas.freeDrawingBrush.strokeDashArray = [20, 50] // 行程破折号数组使用 strokeDashArray 可以设置虚线,里面还可以传2个以上的参数,效果自己试试就明白了。
<br>
投影

// 省略 “起步” 代码canvas.freeDrawingBrush.width = 20 // 画笔宽度// 画笔投影canvas.freeDrawingBrush.shadow = new fabric.Shadow({ blur: 10, // 羽化程度 offsetX: 10, // x轴偏移量 offsetY: 10, // y轴偏移量 color: '#30e3ca' // 投影颜色})<br>
自由绘制被限制为画布大小

// 省略 “起步” 代码canvas.freeDrawingBrush.width = 20 // 画笔宽度canvas.freeDrawingBrush.limitedToCanvasSize = true // 当“ true”时,自由绘制被限制为画布大小。<br>
线条结尾的画笔风格
canvas.freeDrawingBrush.strokeLineCap = 'round'除了 round 之外,还有 butt 或 square 可选。默认是 round。
<br>
画笔的角落风格
canvas.freeDrawingBrush.strokeLineJoin = 'miter'除了 miter 外,还可以选择 bevel 或 round。
<br>
设置笔刷的最大斜接长度
canvas.freeDrawingBrush.strokeLineJoin = 'miter' // 画笔的角落风格canvas.freeDrawingBrush.strokeMiterLimit = 10 // 最大斜接长度strokeMiterLimit 属性的设置适用于 strokeLineJoin 为 miter 的情况。
<br>
<br>
啰嗦两句
笔刷在 Fabric.js 中是一个很基础的工具,也很常用。
常用场景:
- 在线PS画板
- 在线批改操作
<br>
像微信截图那些,也有画笔功能。当然,微信截图的画笔不一定是用 Fabric.js 来实现的,但我们学会 Fabric.js 后也可以说是有能力实现类似的功能了~
<br>
Fabric.js 还提供了其他笔刷,但如果你已经懂得如何使用基础笔刷,那学其他笔刷会更容易上手。
<br>
<br>
代码仓库
<br>
<br>
推荐阅读
点赞 + 关注 + 收藏 = 学会了
边栏推荐
- Splice characters in {{}}
- 运维工作的“本手、妙手、俗手”
- leetcode存在重复元素go实现
- How to configure PostgreSQL 12.9 to allow remote connections
- Domestic all Chinese automatic test software apifox
- ansible安装与使用
- Video multiple effects production, fade in effect and border background are added at the same time
- Fabric.js IText 上标和下标
- [Yu Yue education] autumn 2021 reference materials of Tongji University
- C case of communication between server and client based on mqttnet
猜你喜欢

C case of communication between server and client based on mqttnet

Super detailed pycharm tutorial

VMware installation win10 reports an error: operating system not found

Hcip day 17

Simple and practical accounting software, so that accounts can be checked

06 decorator mode

Cubemx DMA notes

el form 表单validate成功后没有执行逻辑

Pyechart1.19 national air quality exhibition

Analyze the space occupied by the table according to segments, clusters and pages
随机推荐
Online incremental migration of DM database
案例分享|智慧化的西部机场
No logic is executed after the El form is validated successfully
C # picture display occupancy problem
10 minute quick start UI automation ----- puppeter
Analyze the space occupied by the table according to segments, clusters and pages
C# 基于MQTTNet的服务端与客户端通信案例
Cubemx DMA notes
Go implements leetcode rotation array
06 decorator mode
Save the CDA from the disc to the computer
A new attribute value must be added to the entity entity class in the code, but there is no corresponding column in the database table
Simple and practical accounting software, so that accounts can be checked
黑马笔记---Map集合体系
Dark horse notes -- map set system
Draw a wave chart_ Digital IC
TypeScript函数详解
Mysql重点难题(2)汇总
Set the default style of scroll bar Google browser
Typescript function details