簡體   English   中英

用canvg將svg繪制到畫布上

[英]draw svg to canvas with canvg

我在畫布中使用canvg來設置svg文件。 設置svg url時一切正常:

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

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

但是當我嘗試寫(它不起作用)時:

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

其中變量svg獲取manual.svg內容。

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

這是解決問題的一種變體。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM