运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>HTML5 Canvas</h1> <h2>The drawImage() Method</h2> <p>Image to use:</p> <img id="scream" src="../jsref/img_the_scream.jpg" alt="The Scream" width="220" height="277"> <p><button onclick="draw()">Tryit</button></p> <p>Canvas:</p> <canvas id="myCanvas" width="250" height="300" style="border:1px solid grey"></canvas> <script> function draw() { const c = document.getElementById("myCanvas"); const ctx = c.getContext("2d"); const img = document.getElementById("scream"); ctx.drawImage(img, 10, 10, 150, 180); } </script> </body> </html>