資源簡介
首先需要獲取svg標簽以及內容:
var svgHtml = svgContainer.innerHTML();
將svg轉成canvas需要用到google的一個插件canvg
接下來就是調用該插件的canvg(canvasId,svgHtml)方法來轉成canvas,這個方法第一個參數就是canvas標簽的id,第二個自然就是svg標簽內容了,就這樣,svg轉成了canvas
然后就是將canvas轉成圖片了,這個更加簡單了
var imgSrc = document.getElementById(canvasId).toDataUrl("image/png");//這其實是將canvas轉成了圖片,
Use method as shown in the: http://blog.sina.com.cn/s/blog_025270e90101p6vs.html you need to first obtain SVG tag and content: var svgHtml = svgContainer. InnerHTML (); The SVG into canvas need to use the Google a canvg followed by calling the plugin canvg (canvasId svgHtml) method to convert to canvas, this method first parameter is the id tag, the second nature is SVG tag content, and thus, SVG is converted to the canvas and then the canvas into images, the more simple the var imgSrc = document. The getElementById (canvasId). ToDataUrl (& quot; image/png") ; / / this is the canvas into the image,.
代碼片段和文件信息
評論
共有 條評論