当前位置:网站首页>Fabric. JS compact JSON
Fabric. JS compact JSON
2022-07-02 05:18:00 【Director of Moral Education Department】
Brief introduction
give the thumbs-up + Focus on + Collection = Learned to
<br>
If you don't know much about Fabric.js Serialization and deserialization of , You can see Fabric.js serialize and Fabric.js Deserialization .
<br>
This article will talk about “ Streamlining JSON” It's actually Compact serialization . Serialization can put Fabric.js The canvas of is exported as a JSON object .
When we want to save the canvas to the server , What is transmitted to the background is actually a segment JSON . If you want to re render , Just put this paragraph JSON Throw it to Fabric.js , Call the corresponding method to render to the page .
But if you think Fabric.js Default exported JSON Too big 、 If you don't need so many attributes , You can use a thin version of the configuration .
<br>
<br>
Hands on coding
Compare the default export with the compact Export .

I added... To the page 1 A background picture and 2 Basic graphic elements , If you use the default serialization , The object is really a little more .
If you only need core attributes , Just for rendering , That can be used “ Thin serialization ”.
<canvas id="canvasBox" width="600" height="600" style="border: 1px solid #ccc;"></canvas><!-- introduce Fabric.js --><script src="https://cdn.bootcdn.net/ajax/libs/fabric.js/521/fabric.js"></script><script> // Initialize canvas canvas = new fabric.Canvas('canvasBox', { includeDefaultValues: false // instructions toObject/toDatalessObject Whether the default value should be included , If set to false, Takes precedence over the object value }) console.log(canvas.toObject()) // Output serialized content </script>《canvas.includeDefaultValues file 》
take includeDefaultValues Set to false You can make canvas.toObject() Method outputs a reduced JSON .
includeDefaultValues The default value of is true , So the basic version will be output by default JSON Content .
<br>
You can modify it includeDefaultValues Value , Observe the changes of the output object .
<br>
I need to remind you : If your project needs only to see results , You don't need to worry about too many internal attributes , You can try to use the content mentioned in this article , The reduced data is transmitted to the back end , This saves space .
<br>
Careful students should also see , Even after the reduction JSON data , The version number will still be saved in it . If the version number doesn't work for you , You can also use it JS The method of version Get rid of . But I don't suggest you do this .
<br>
<br>
Source warehouse
<br>
<br>
Recommended reading
《Fabric.js How to use the brush ?》
《Fabric.js How to use an eraser ( Including recovery function )》
《Fabric.js From entry to defiance 》
give the thumbs-up + Focus on + Collection = Learned to
边栏推荐
- Nodejs (02) - built in module
- Mathematical knowledge -- understanding and examples of fast power
- 在{{}}中拼接字符
- Map in JS (including leetcode examples)
- Differential identities (help find mean, variance, and other moments)
- [high speed bus] Introduction to jesd204b
- C case of communication between server and client based on mqttnet
- How matlab marks' a 'in the figure and how matlab marks points and solid points in the figure
- Record my pytorch installation process and errors
- ubuntu20.04安装mysql8
猜你喜欢

Nodejs (03) -- custom module

Summary of database problems

Pyechats 1.19 generate a web version of Baidu map

Differential identities (help find mean, variance, and other moments)

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

4. Flask cooperates with a tag to link internal routes
![[common error] the DDR type of FPGA device is selected incorrectly](/img/f3/be66bcfafeed581add6d48654dfe34.jpg)
[common error] the DDR type of FPGA device is selected incorrectly

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
![[high speed bus] Introduction to jesd204b](/img/78/1a0a3672e63058da6d98da95aa3cf2.jpg)
[high speed bus] Introduction to jesd204b
![Gee series: unit 9 generate sampling data in GEE [random sampling]](/img/ff/edb27b40f63eca81c5683e81b2860b.jpg)
Gee series: unit 9 generate sampling data in GEE [random sampling]
随机推荐
[common error] the DDR type of FPGA device is selected incorrectly
2022 Alibaba global mathematics competition, question 4, huhushengwei (blind box problem, truck problem) solution ideas
操作符详解
Summary of MySQL key challenges (2)
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
CubeMx DMA笔记
Global and Chinese markets for marine selective catalytic reduction systems 2022-2028: Research Report on technology, participants, trends, market size and share
Feign realizes file uploading and downloading
Black Horse Notes - - set Series Collection
Gee series: unit 10 creating a graphical user interface using Google Earth engine [GUI development]
Mysql重点难题(2)汇总
Video multiple effects production, fade in effect and border background are added at the same time
摆正元素(带过渡动画)
黑马笔记---Map集合体系
Domestic all Chinese automatic test software apifox
Fabric.js 3个api设置画布宽高
7.1模拟赛总结
Disable access to external entities in XML parsing
4. Flask cooperates with a tag to link internal routes
线程池批量处理数据