简体   繁体   English

用canvg将svg绘制到画布上

[英]draw svg to canvas with canvg

I use canvg for set svg file in canvas. 我在画布中使用canvg来设置svg文件。 All is ok when I set svg url: 设置svg url时一切正常:

var canvas = doc.getCanvas(num);
var context = canvas.getContext('2d');

context.drawSvg("http://localhost:8084/manual.svg", 0, 0, width, height);

But when I try to write (it doesn't work): 但是当我尝试写(它不起作用)时:

context.drawSvg("data:image/svg+xml,"+svg, 0, 0, width, height);

where variable svg get manual.svg content. 其中变量svg获取manual.svg内容。

img.src = "data:image/svg+xml;base64,"+btoa(svgContent);
context.drawImage(img, 0, 0, width, height);

it's one variant to solve the problem. 这是解决问题的一种变体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM