在Canvas上绘图时,如何在JavaScript中为文本提供大纲?请参阅下面我尝试做的图片。
答案 0 :(得分: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);
答案 1 :(得分: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);