HTML5 canvas显示图片drawImage

<!DOCTYPE HTML>
<html>
<body>

<canvas id="myCanvas" width="500" height="500" style="border:1px solid #c3c3c3;"></canvas>

<script type="text/javascript">

var c = document.getElementById("myCanvas");
var cxt = c.getContext("2d");

var img = new Image();
img.src = "./cat.jpg";
cxt.drawImage(img, 0, 0);
img.onload = function() {
    // cxt.clearRect(0, 0, c.width, c.height);
    cxt.drawImage(img, 0, 0);
};

</script>

</body>
</html>


发表于:2017-10-13 13:52:08

原文链接(转载请保留): http://www.multisilicon.com/blog/a25306125.html

友情链接: MICROIC
首页