当前位置:网站首页>Fabric. JS basic brush
Fabric. JS basic brush
2022-07-02 05:18:00 【Director of Moral Education Department】
Brief introduction
give the thumbs-up + Focus on + Collection = Learned to
<br>
Fabric.js
Turn on the painting mode , You can set the style of the brush .
There are several kinds of brushes , This paper mainly introduces Fabric
Basic brush usage .
Before written 《Fabric.js How to use an eraser 》 Drawing mode is also used , Those who are interested can go and have a look .
<br>
This article USES the
Fabric.js 5.2.1
<br>
<br>
Common configuration
First of all, start the painting mode of canvas , Because the normal box selection mode does not support painting .
<br>
start
<canvas id="c" width="600" height="400" style="border: 1px solid #ccc;"></canvas><!-- introduce 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 // Turn on painting mode })</script>
take isDrawingMode
Set to true
Can be opened , This is an important step , Only settings isDrawingMode
by true
, The following operations in this article are meaningful .
If you do not want to set... During initialization isDrawingMode
, It can also be used later canvas.isDrawingMode = true
How to set .
<br>
Be careful : All the following operations are based on “ start ” Code for !!!
<br>
Set the brush width
// Omit “ start ” Code canvas.freeDrawingBrush.width = 20 // The width of the brush
It can be modified by width
Adjust the brush thickness .
<br>
Set brush color
// Omit “ start ” Code canvas.freeDrawingBrush.width = 20 // The width of the brush canvas.freeDrawingBrush.color = 'pink' // Brush color
I set the width of the brush to 20, It's easier to show the effect .
<br>
Dotted line
// Omit “ start ” Code canvas.freeDrawingBrush.width = 20 // The width of the brush canvas.freeDrawingBrush.strokeDashArray = [20, 50] // Stroke dash array
Use strokeDashArray
Dotted lines can be set , It can also be passed on 2 More than parameters , Try the effect yourself and you'll see .
<br>
Projection
// Omit “ start ” Code canvas.freeDrawingBrush.width = 20 // The width of the brush // Brush projection canvas.freeDrawingBrush.shadow = new fabric.Shadow({ blur: 10, // The degree of eclosion offsetX: 10, // x Shaft offset offsetY: 10, // y Shaft offset color: '#30e3ca' // Projection color })
<br>
Freehand painting is limited to canvas size
// Omit “ start ” Code canvas.freeDrawingBrush.width = 20 // The width of the brush canvas.freeDrawingBrush.limitedToCanvasSize = true // When “ true” when , Freehand painting is limited to canvas size .
<br>
Brush style at the end of the line
canvas.freeDrawingBrush.strokeLineCap = 'round'
except round
outside , also butt
or square
Optional . The default is round
.
<br>
The corner style of the brush
canvas.freeDrawingBrush.strokeLineJoin = 'miter'
except miter
Outside , You can also choose bevel
or round
.
<br>
Set the maximum miter length of the brush
canvas.freeDrawingBrush.strokeLineJoin = 'miter' // The corner style of the brush canvas.freeDrawingBrush.strokeMiterLimit = 10 // Maximum miter length
strokeMiterLimit
Property is set for strokeLineJoin
by miter
The situation of .
<br>
<br>
long-winded
Brush in Fabric.js
Is a very basic tool , Also very common .
Common scenarios :
- On-line PS Drawing board
- Online correction operation
<br>
Like wechat screenshots , There is also a brush function . Of course , The brush for wechat screenshots is not necessarily Fabric.js
To achieve , But we learned Fabric.js
It can also be said that it has the ability to realize similar functions ~
<br>
Fabric.js
Other brushes are also available , But if you already know how to use basic brushes , It will be easier to learn other brushes .
<br>
<br>
Code warehouse
<br>
<br>
Recommended reading
- 《Fabric.js Draw ellipses freely 》
- 《Fabric.js How to use an eraser ( Including recovery function )》
- 《Fabric.js Customize the right-click menu 》
- 《Fabric.js From entry to expansion 》
give the thumbs-up + Focus on + Collection = Learned to
边栏推荐
- Gee: create a new feature and set corresponding attributes
- ubuntu20.04安装mysql8
- 运维工作的“本手、妙手、俗手”
- Mapping settings in elk (8) es
- Domestic all Chinese automatic test software apifox
- Summary of database problems
- Mysql基础---查询(1天学会mysql基础)
- 7.1模拟赛总结
- LeetCode 241. 为运算表达式设计优先级(分治/记忆化递归/动态规划)
- Mathematical knowledge -- understanding and examples of fast power
猜你喜欢
指针使用详解
Gee series: Unit 1 Introduction to Google Earth engine
Gee: remote sensing image composite and mosaic
Disable access to external entities in XML parsing
Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
操作符详解
Using QA band and bit mask in Google Earth engine
Latest: the list of universities and disciplines for the second round of "double first-class" construction was announced
Johnson–Lindenstrauss Lemma(2)
Gee: analyze the change of spatial centroid of remote sensing image [centroid acquisition analysis]
随机推荐
Disable access to external entities in XML parsing
Ubuntu 20.04 installing mysql8
【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘
Ls1046nfs mount file system
Johnson–Lindenstrauss Lemma(2)
Fabric. JS 3 APIs to set canvas width and height
Fabric.js 圆形笔刷
Fabric.js 激活输入框
Video multiple effects production, fade in effect and border background are added at the same time
Video cover image setting, put cover images into multiple videos in the simplest way
Global and Chinese market of commercial fish tanks 2022-2028: Research Report on technology, participants, trends, market size and share
Black Horse Notes - - set Series Collection
Oracle和MySQL的基本区别(入门级)
Pyechats 1.19 generate a web version of Baidu map
Fabric.js 自由绘制矩形
Dark horse notes -- map set system
Gee series: unit 9 generate sampling data in GEE [random sampling]
2022阿里巴巴全球数学竞赛 第4题 虎虎生威(盲盒问题、集卡问题)解决思路
Nodejs (03) -- custom module
Pyechart1.19 national air quality exhibition