当前位置:网站首页>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
边栏推荐
- Global and Chinese markets for marine selective catalytic reduction systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of cell culture freezers 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of travel data recorder (VDR) 2022-2028: Research Report on technology, participants, trends, market size and share
- php/js cookie共享跨域的问题
- Global and Chinese market of hydrocyclone desander 2022-2028: Research Report on technology, participants, trends, market size and share
- Fabric.js IText设置指定文字的颜色和背景色
- 7.1模擬賽總結
- 设置滚动条默认样式 谷歌浏览器
- Mathematical knowledge -- understanding and examples of fast power
- Fabric.js 背景不受视口变换影响
猜你喜欢

黑马笔记---Map集合体系
![Gee: analyze the change of spatial centroid of remote sensing image [centroid acquisition analysis]](/img/25/a726643b96b6f7dbfee3782c4905d9.jpg)
Gee: analyze the change of spatial centroid of remote sensing image [centroid acquisition analysis]

摆正元素(带过渡动画)

视差特效的原理和实现方法

Gee: create a new feature and set corresponding attributes

paddle: ValueError:quality setting only supported for ‘jpeg‘ compression

Fabric.js IText设置指定文字的颜色和背景色

黑馬筆記---Set系列集合

Ls1046nfs mount file system

LeetCode 241. Design priorities for operational expressions (divide and conquer / mnemonic recursion / dynamic programming)
随机推荐
Dark horse notes -- Set Series Collection
ERP management system development and design existing source code
Two implementation methods of delay queue
【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
Feign realizes file uploading and downloading
Global and Chinese market of cell culture freezers 2022-2028: Research Report on technology, participants, trends, market size and share
Simple and practical accounting software, so that accounts can be checked
Video multiple effects production, fade in effect and border background are added at the same time
从数组中找出和为目标的下标
Fabric. JS 3 APIs to set canvas width and height
The underlying principle of go map (storage and capacity expansion)
[high speed bus] Introduction to jesd204b
2022 Alibaba global mathematics competition, question 4, huhushengwei (blind box problem, truck problem) solution ideas
7.1模拟赛总结
Thread pool batch processing data
Collectors. Groupingby sort
创新永不止步——nVisual网络可视化平台针对Excel导入的创新历程
Pyflink writes MySQL examples with JDBC
Johnson–Lindenstrauss Lemma(2)
Splice characters in {{}}