How can I give a text an outline in JavaScript when drawing on the Canvas? See image below of what I try to do.
user16094
问问题
6759 次
2 回答
7
Daniel Langh 向我展示了解决方案:
var txt = 'Hello World!';
var x = 30,
y = 50;
context.font = "40px Helvetica";
context.strokeStyle = 'white';
// setup these to match your needs
context.miterLimit = 2;
context.lineJoin = 'circle';
// draw an outline, then filled
context.lineWidth = 7;
context.strokeText(txt, x, y);
context.lineWidth = 1;
context.fillText(txt, x, y);
于 2013-01-03T10:15:41.937 回答
0
您可以尝试使用 strokeText 来描边轮廓:
var context = document.getElementById("d").getContext("2d");
context.font = "bold 34px sans-serif";
context.fillText('office space', 50, 60);
context.strokeStyle = 'white';
context.lineWidth = 2;
context.strokeText('office space', 50, 60);
于 2013-01-02T18:09:53.470 回答