当前位置:网站首页>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>
推荐阅读
点赞 + 关注 + 收藏 = 学会了
边栏推荐
- Video cover image setting, put cover images into multiple videos in the simplest way
- Collectors. Groupingby sort
- 画波形图_数字IC
- go实现leetcode旋转数组
- [common error] the DDR type of FPGA device is selected incorrectly
- Essence and physical meaning of convolution (deep and brief understanding)
- [quick view opencv] familiar with CV matrix operation with image splicing examples (3)
- Johnson–Lindenstrauss Lemma(2)
- 删除排序数组中的重复项go语言实现
- Hcip day 17
猜你喜欢

LM09丨费雪逆变换反转网格策略

LeetCode 241. Design priorities for operational expressions (divide and conquer / mnemonic recursion / dynamic programming)

Dark horse notes -- map set system

创新永不止步——nVisual网络可视化平台针对Excel导入的创新历程

数据库问题汇总

Video cover image setting, put cover images into multiple videos in the simplest way

Line by line explanation of yolox source code of anchor free series network (7) -- obj in head_ loss、Cls_ Loss and reg_ Calculation and reverse transmission of loss I

06 装饰(Decorator)模式

Detailed process of DC-1 range construction and penetration practice (DC range Series)

Rhcsa --- work on the third day
随机推荐
JS interview collection test question 1
Future trend of automated testing ----- self healing technology
Find the subscript with and as the target from the array
6.30年终小结,学生时代结束
Mouse events in JS
Express logistics quick query method, set the unsigned doc No. to refresh and query automatically
Set the default style of scroll bar Google browser
Change deepin to Alibaba image source
Dark horse notes -- Set Series Collection
Black Horse Notes - - set Series Collection
[Yu Yue education] autumn 2021 reference materials of Tongji University
删除排序数组中的重复项go语言实现
Fabric.js IText设置指定文字的颜色和背景色
Learn BeanShell before you dare to say you know JMeter
Detailed process of DC-1 range construction and penetration practice (DC range Series)
How to modify data file path in DM database
leetcode存在重复元素go实现
10 minute quick start UI automation ----- puppeter
2022阿里巴巴全球数学竞赛 第4题 虎虎生威(盲盒问题、集卡问题)解决思路
LeetCode 241. 为运算表达式设计优先级(分治/记忆化递归/动态规划)