<!DOCTYPE html> <html><body> <canvas id="canvas" width="512" height="512"> </canvas> <script type="text/javascript"> var img = document.createElement("IMG"); img.onload = function() { var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); ctx.clearRect( 0, 0, canvas.width, canvas.height); // 描画色などの設定 ctx.strokeStyle = "rgb(255, 0, 0)"; ctx.fillStyle = "rgba(255, 0, 0, 0.5)"; ctx.lineWidth = 4; // 画像の描画 ctx.drawImage( img, 512-img.width, 512-img.height);
// 矩形の描画 ctx.fillRect(4, 4, 256, 256); ctx.strokeRect(4, 4, 256, 256); // パスの描画 ctx.beginPath(); ctx.arc(200, 400, 100, 0, 1.5*Math.PI, false); ctx.lineTo(200, 400); ctx.closePath(); ctx.fill(); ctx.stroke(); // テキストの描画 ctx.fillStyle = "black"; ctx.strokeStyle = "white"; ctx.lineWidth = 1.5; ctx.font = "bold 40px sans-serif"; ctx.fillText("DevFest 2010", 120, 100); ctx.strokeText("DevFest 2010", 120, 100); } img.src = "../images/sample_photo.jpg"; </script> </body></html>