+ 1

Canvas text?

How can i put text on a canvas

7th Jul 2022, 9:54 PM
Bogyo - Leția Eduard
Bogyo - Leția Eduard - avatar
1 Answer
+ 1
You can use the `strokeText` and `fillText` methods of a `2DCanvasRenderingContext`. For example: ``` // assuming there’s a canvas in the DOM with the id “canvas” const canvas = document.getElementById(“canvas”); const ctx = canvas.getContext(“2d”); ctx.fillStyle = “white”; // #ffffff ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fillStyle = “black”; // #000000 ctx.font = “20px Times New Roman”; ctx.fillText(“Hello world!”, 10, 10); ctx.strokeText(“Hello world!”, 10, 30); ```
10th Jul 2022, 10:43 AM
Matthew James
Matthew James - avatar