HTML5 draws text in canvas with renderings
This article mainly introduces how to draw text in canvas in HTML5. There are two methods to draw text in canvas, strokeText and fillText, which can be selected according to your needs.
1. Draw text
In the drawing environment, two methods are provided to draw text in canvas.
strokeText(text,x,y): Draw hollow text at (x,y).
fillText(text,x,y): Draw solid text at (x,y).
2. Draw text in canvas
The code is as follows:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset = utf-8"> <title>HTML5</title> <script type="text/javascript" charset = "utf-8"> //这个函数将在页面完全加载后调用 function pageLoaded() { //获取canvas对象的引用,注意tCanvas名字必须和下面body里面的id相同 var canvas = document.getElementById('tCanvas'); //获取该canvas的2D绘图环境 var context = canvas.getContext('2d'); //绘制代码将出现在这里 //绘制文本 context.fillText('Welcome to DuJun Blog',100,40); //修改字体 context.font = '20px Arial'; context.fillText('Welcome to DuJun Blog',100,100); //绘制空心的文本 context.font = '36px 隶书'; context.strokeText('欢迎来到笃军的博客',100,200); } </script> </head> <body onload="pageLoaded();"> <canvas width = "500" height = "300" id = "tCanvas" style = "border:black 1px solid;"> <!--如果浏览器不支持则显示如下字体--> 提示:你的浏览器不支持<canvas>标签 </canvas> </body> </html>
3 , drawing effect
The above is the entire content of this chapter. For more related tutorials, please visit Html5 video tutorial!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.
