Hello World

HTML

<canvas id="canvas" width=300 height=100 style="background-color:#808080;">
</canvas>

使用 Javascript

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.font = "34px serif";
ctx.textAlign = "center";
ctx.textBaseline="middle"; 
ctx.fillStyle = "#FFF";
ctx.fillText("Hello World",150,50);

结果

StackOverflow 文档