var url = canvas.toDataURL();
var myimg=document.getElementById('myimg');
myimg.src = url;
-
<!DOCTYPE HTML>
-
-
<html>
-
-
<body>
-
-
-
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;">
-
-
Your browser does not support the canvas element.
-
-
</canvas>
-
-
-
-
<input type="button" name="button" value="button" onclick="convertCanvasToImage()"/>
-
<image src="" alt="" id="myimg" width="100px;" height="100px;"/>
-
<script type="text/javascript">
-
-
-
var c=document.getElementById("myCanvas");
-
-
var cxt=c.getContext("2d");
-
cxt.moveTo(10,10);
-
-
cxt.lineTo(150,50);
-
-
cxt.lineTo(10,50);
-
-
cxt.stroke();
-
-
-
</script>
-
-
-
-
<script type="text/javascript">
-
-
function convertCanvasToImage() {
-
alert(22);
-
var canvas = document.getElementById('myCanvas');
-
var url = canvas.toDataURL();
-
var myimg=document.getElementById('myimg');
-
myimg.src = url;
-
}
-
-
-
</script>
-
-
-
</body>
-
-
</html>
阅读(682) | 评论(0) | 转发(0) |