Javascript 如何在HTML5画布上添加边框&x27;文本?
我可以使用下面的代码绘制文本Javascript 如何在HTML5画布上添加边框&x27;文本?,javascript,html,canvas,Javascript,Html,Canvas,我可以使用下面的代码绘制文本 myCanvas.fillStyle = "Red"; myCanvas.font = "30pt Arial"; myCanvas.fillText("Some Text", 10, 30); 但是我想在“一些文本”周围加一个边框,有什么想法吗?怎么样 myCanvas.style.border = "red 1px solid"; 使用strokeText()和strokeStyle.例如: canvas=document.getElementById(“
myCanvas.fillStyle = "Red";
myCanvas.font = "30pt Arial";
myCanvas.fillText("Some Text", 10, 30);
但是我想在“一些文本”周围加一个边框,有什么想法吗?怎么样
myCanvas.style.border = "red 1px solid";
使用strokeText()
和strokeStyle.
例如:
canvas=document.getElementById(“myc”);
context=canvas.getContext('2d');
context.fillStyle='red';
context.strokeStyle='black';
context.font='20pt Verdana';
context.fillText('Some text',50,50);
strokeText('Some text',50,50);
context.fill();
stroke()代码>
我们可以使用strokeStyle方法在文本或轮廓周围绘制边框,也可以使用lineWidth方法定义笔划线的宽度
var canvas=document.getElementById('Canvas01');
var ctx=canvas.getContext('2d');
ctx.strokeStyle=“红色”//设置笔划线的颜色
ctx.lineWidth=3//定义笔划线的宽度
ctx.font=“italic bold 35pt Tahoma”//设置字体名称和字体大小
ctx.strokeText(“StackOverFlow”,30,80)//绘制文本
这会在画布中添加边框,而不是在画布中绘制的文本中添加边框;我假设op想要在字母本身的形状中创建一个边框。哇!我以前从未见过这样一个“可执行”的答案。这是一个新功能吗?因为字体很大,所以可以工作,但是如果字体很小,那么就不能工作了