用canvg将svg绘制到画布

问题描述:

我使用canvg在画布中设置svg文件. 设置svg网址时一切正常:

I use canvg for set svg file in canvas. All is ok when I set 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);

其中svg变量获取manual.svg内容.

where variable svg get manual.svg content.

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

这是解决问题的一种方法.

it's one variant to solve the problem.