啥也不说,直接上代码。
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="svg-wrap">
<svg width="200" height="200" xmlns='http://www.w3.org/2000/svg'>
<rect width="200" height="200" style="fill:#ddd"></rect>
</svg>
</div>
<canvas id="canvas"></canvas>
<script>
window.onload = function(){
//获取svg内容
var svg = document.getElementById('svg-wrap').innerHTML;
var canvas = document.getElementById('canvas');
var c = canvas.getContext('2d');
//新建Image对象
var img = new Image();
//svg内容
img.src = 'data:image/svg+xml,' + unescape