How can I write text on a HTML5 canvas element?

前端 未结 8 1079
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 21:36

Is it possible to write text on HTML5 canvas?

8条回答
  •  庸人自扰
    2020-11-28 22:04

    var canvas = document.getElementById("my-canvas");
    var context = canvas.getContext("2d");
    
    context.fillStyle = "blue";
    context.font = "bold 16px Arial";
    context.fillText("Zibri", (canvas.width / 2) - 17, (canvas.height / 2) + 8);
    #my-canvas {
      background: #FF0;
    }

提交回复
热议问题