Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Canvas context.fillText() vs context.strokeText()

Tags:

html

canvas

Is there any difference between context.fillText() and context.strokeText() besides the fact that the first uses context.fillStyle while the later uses context.strokeStyle. Any reason they did not add a context.textStyle property?

like image 228
Hoffmann Avatar asked Sep 12 '14 21:09

Hoffmann


1 Answers

var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = 'red';
ctx.strokeStyle = 'green'
ctx.lineWidth = 3;
ctx.font = '90px verdana';
ctx.fillText('Q', 50, 100);
ctx.strokeText('Q', 125, 100);
ctx.fillText('Q', 200, 100);
ctx.strokeText('Q', 200, 100);
<canvas id="myCanvas"></canvas>

Yep, strokeText actually strokes the outline of the letters while fillText fills the inside of the letters.

enter image description here

like image 117
markE Avatar answered Oct 17 '22 02:10

markE