运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>HTML5 Canvas</h1> <h2>The imgData.height Property</h2> <canvas id="myCanvas" width="300" height="150" style="border:1px solid grey"></canvas> <p id="demo"></p> <script> const c = document.getElementById("myCanvas"); const ctx = c.getContext("2d"); const imgData = ctx.createImageData(100, 100); for (let i = 0; i < imgData.data.length; i += 4) { imgData.data[i+0] = 255; imgData.data[i+1] = 0; imgData.data[i+2] = 0; imgData.data[i+3] = 255; } ctx.putImageData(imgData, 10, 10); document.getElementById("demo").innerHTML = "Height is: " + imgData.height; </script> </body> </html>