当前位置:网站首页>js----SVG转PNG
js----SVG转PNG
2022-06-22 20:50:00 【紫微前端】
/**
* @desc SVG转PNG
* @param {Object} o 转入参数
* @param {Element} o.svg svg 节点
* @param {Number} o.scale 缩放
* @param {String} o.toDataType 输出数据类型 toDataURL||toBlob
* @param {Function} o.success 成功回调
* @param {Function} o.error 失败回调
*/
function svg2png(o) {
let svg = o.svg;
let scale = o.scale || 1;
let toDataType = o.toDataType || "toDataURL";
let success = o.success || function () { };
let error = o.error || function () { };
let svgData = new XMLSerializer().serializeToString(svg);
let canvas = document.createElement("canvas");
let svgSize = svg.getBoundingClientRect();
canvas.width = svgSize.width * scale;
canvas.height = svgSize.height * scale;
// canvas.style.width = svgSize.width;
// canvas.style.height = svgSize.height;
let ctx = canvas.getContext("2d");
ctx.scale(scale边栏推荐
- SQL performance optimization method for interval retrieval
- 安装typescript环境并开启VSCode自动监视编译ts文件为js文件
- Cryptography series: certificate format representation of PKI X.509
- How to quickly build an enterprise knowledge base at low cost?
- 2020-12-04
- A SQL optimization case using order by and rownum
- 2021-04-14
- Spark SQL Generic Load/Save Functions(2.4.3)
- ArcGIS application (20) the ArcGIS grid image symbol system prompts "this dataset does not have valid histogram required for classificati..."
- 《强化学习周刊》第50期:SafeRL-Kit、GMI-DRL、RP-SDRL & 离线元强化学习
猜你喜欢
Summary of transport layer knowledge points

Explain the startup process of opengauss multithreading architecture in detail

LinkedList source code analysis

Three cache methods and principles

C language -- 17 function introduction

The relationship between derivative and differential of function

2021-08-26

Is it bad for NFT that the market starts to cool down?

安装typescript环境并开启VSCode自动监视编译ts文件为js文件
Several ways of redis persistence -- deeply parsing RDB
随机推荐
NFT can only be viewed from afar, but not blatantly played
AutoCAD - five annotation shortcuts
5 minutes to quickly launch web applications and APIs (vercel)
Valid parentheses
SqlServer 复制表的自增属性
Task management of embedded development foundation (thread management)
R language data preprocessing, converting type variables into factor variables, converting data sets into H2O format, and dividing data sets (training set, test set, verification set)
ArcGIS application (20) the ArcGIS grid image symbol system prompts "this dataset does not have valid histogram required for classificati..."
Learn redis with you (11) -- redis distributed lock
为 localStorage 添加过期时间
使用Redisson操作分布式队列的注意事项
A spark app demo
The xinjietu x70s has been listed for 87900 times and has leapfrogged the class in space safety. It is worthy of being a 7-seat SUV of the National University of China
Help customers' digital transformation and build a new operation and maintenance system
c语言---17 函数简介
Phantomjs实用代码段(持续更新中……)
A group of K overturned linked lists [disassembly / overturning / assembly of linked lists]
Install the typescript environment and enable vscode to automatically monitor the compiled TS file as a JS file
Business stability construction ideas based on Cloud Architecture
2021-04-14