当前位置:网站首页>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
边栏推荐
- Gee: explore the change of water area in the North Canal basin over the past 30 years [year by year]
- Gee series: unit 6 building various remote sensing indexes in Google Earth engine
- 数据库问题汇总
- Record my pytorch installation process and errors
- Global and Chinese market of impact roll 2022-2028: Research Report on technology, participants, trends, market size and share
- Gee series: unit 8 time series analysis in Google Earth engine [time series]
- Express logistics quick query method, set the unsigned doc No. to refresh and query automatically
- Domestic all Chinese automatic test software apifox
- Gee: find the spatial distribution and corresponding time of the "greenest" in the Yellow River Basin in 2020 [pixel by pixel analysis]
- 黑馬筆記---Set系列集合
猜你喜欢

Save the CDA from the disc to the computer

Fabric.js 渐变

函数栈帧的创建和销毁
![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]

操作符详解
![[opencv] image binarization](/img/7e/b56a59ffae3bf6cac9c0bb7e090b85.jpg)
[opencv] image binarization
![Gee: use of common mask functions in remote sensing image processing [updatemask]](/img/55/bf4ef5fc923242e72caab71f1a4e4b.jpg)
Gee: use of common mask functions in remote sensing image processing [updatemask]

The underlying principle of go map (storage and capacity expansion)

The El cascader echo only selects the questions that are not displayed

LeetCode 241. 为运算表达式设计优先级(分治/记忆化递归/动态规划)
随机推荐
画波形图_数字IC
[bus interface] Axi interface
Express logistics quick query method, set the unsigned doc No. to refresh and query automatically
Global and Chinese market of insulin pens 2022-2028: Research Report on technology, participants, trends, market size and share
ERP management system development and design existing source code
Fabric.js IText设置指定文字的颜色和背景色
Collectors. Groupingby sort
Gee: remote sensing image composite and mosaic
C case of communication between server and client based on mqttnet
Global and Chinese market of impact roll 2022-2028: Research Report on technology, participants, trends, market size and share
Using QA band and bit mask in Google Earth engine
Fabric.js 更换图片的3种方法(包括更换分组内的图片,以及存在缓存的情况)
数据库问题汇总
The reason why sizeof (ARR) / sizeof (arr[0]) is used in the function to calculate the length of the array is incorrect
[high speed bus] Introduction to jesd204b
数据的储存
Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
paddle: ValueError:quality setting only supported for ‘jpeg‘ compression
Pyflink writes MySQL examples with JDBC
Global and Chinese markets for marine selective catalytic reduction systems 2022-2028: Research Report on technology, participants, trends, market size and share