当前位置:网站首页>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 market of hydrocyclone desander 2022-2028: Research Report on technology, participants, trends, market size and share
- [bus interface] Axi interface
- 数据库批量插入数据
- National all Chinese Automatic Test Software apifox
- Storage of data
- Fabric.js IText设置指定文字的颜色和背景色
- 国产全中文-自动化测试软件Apifox
- Gee series: unit 7 remote sensing image classification using GEE [random forest classification]
- Fabric.js 精简JSON
- 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
猜你喜欢
随机推荐
函数栈帧的创建和销毁
Black Horse Notes - - set Series Collection
C case of communication between server and client based on mqttnet
国产全中文-自动化测试软件Apifox
Implementation of leetcode two number addition go
paddle: ValueError:quality setting only supported for ‘jpeg‘ compression
[opencv] image binarization
黑馬筆記---Set系列集合
Using Kube bench and Kube hunter to evaluate the risk of kubernetes cluster
Gee: find the spatial distribution and corresponding time of the "greenest" in the Yellow River Basin in 2020 [pixel by pixel analysis]
Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]
LeetCode 1175. Prime number arrangement (prime number judgment + Combinatorial Mathematics)
Find the subscript with and as the target from the array
Leetcode basic programming: array
Ubuntu 20.04 installing mysql8
【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘
Gee: explore the characteristics of precipitation change in the Yellow River Basin in the past 10 years [pixel by pixel analysis]
Fabric.js 居中元素
Leetcode 18 problem [sum of four numbers] recursive solution
Summary of database problems



![Gee series: unit 10 creating a graphical user interface using Google Earth engine [GUI development]](/img/78/a17034d4b77d5c0dbe741f84a8ecd7.jpg)



