Canvas text? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Resposta
+ 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