要使用HTML5 Canvas设置文本颜色,我们可以将画布上下文的fillStyle属性设置为颜色字符串,十六进制值或RGB值。
<!DOCTYPE HTML>
<html>
<head>
<style>
body { margin: 0px;padding: 0px;}
</style>
</head>
<body>
<canvas id="myCanvas" width="578" height="200"></canvas>
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
context.font = '40pt Calibri';
context.fillStyle = 'blue';
context.fillText('Hello World!', 150, 100);
</script>
</body>
</html>