<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>hoge</title> </head> <body> <canvas id="e2" width="256" height="268"></canvas> <canvas id="e3" width="256" height="268"></canvas> <script> var canvas2 = document.getElementById("e2"); var context2 = canvas2.getContext("2d"); var fist2 = new Image(); fist2.src = "./html5-fist.png"; fist2.onload = function() { context2.drawImage(fist2, 0, 0); }; var canvas = document.getElementById("e3"); var context = canvas.getContext("2d"); var fist = new Image(); fist.src = "./html5-fist.png"; fist.onload = function() { for (var x = 0, y = 0; x < 500 && y < 375; x += 20, y += 27) { context.drawImage(fist, x, y, 50, 50); } }; </script> </body> </html>
普通にimgからでも使えるけど、Imageオブジェクトを生成して
canvasで描画することも可能である。
- 作者: Mark Pilgrim,矢倉眞隆(監訳),水原文
- 出版社/メーカー: オライリージャパン
- 発売日: 2011/04/23
- メディア: 大型本
- 購入: 12人 クリック: 350回
- この商品を含むブログ (13件) を見る