将svg转为png,jpg等图片类型。
js
const image = new Image();
// image.src =
// 'data:image/svg+xml;base64,' +
// window.btoa(unescape(encodeURIComponent(svg)));
image.src = './xxx.svg';
image.onload = function () {
var canvas = document.createElement('canvas');
canvas.width = 6400;
canvas.height = 3400;
var context = canvas.getContext('2d');
context.drawImage(image, 0, 0);
var a = document.createElement('a');
a.href = canvas.toDataURL('image/png', 1);
a.download = 'xxx.png';
a.click();
};