用canvg将svg绘制到画布 [英] draw svg to canvas with canvg

查看:434
本文介绍了用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.

这篇关于用canvg将svg绘制到画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆