在canvas中插入图片

html

    <canvas id="myCanvas" width="400" height="400" style="border: 2px solid grey">当前浏览器不支持canvas</canvas>

js

var canvas = document.getElementById("myCanvas")
var context = canvas.getContext("2d")

var img = new Image()
img.src = 'paddle.png'
//图片加载完后,将其显示在canvas中
img.onload = function(){
    context.drawImage(this, 0, 0)
    // context.drawImage(this, 0, 0, 1080, 980)改变图片大小到1080*980
}

之前犯了个错误是把2d写成2D,就一直显示不出来,鹅鹅鹅

posted @ 2018-07-13 16:51  五个唔  阅读(19616)  评论(0编辑  收藏  举报