HTML:

<body>
<canvas id="mycanvas" width="640" height="450"></canvas>
<img src="" alt=""/>
</body>

JS代码:
var canvas = document.getElementById("mycanvas");
var context = canvas.getContext('2d');
var cw = 640;
var ch = 450;
context.fillStyle = "#ff0000";
context.fillRect(0, 0, cw, ch);
var img=new Image();
img.src="images/12.jpeg";
context.drawImage(img,0,0, cw,ch);   

var imgData =canvas.toDataURL("image/png");  
$("body img").attr("src",imgData);

 




posted on 2015-06-03 17:40  神经质女孩  阅读(4064)  评论(0编辑  收藏  举报