我可以借鉴使用下面的代码文本,如何在HTML5 Canvas的文本上添加边框?
myCanvas.fillStyle = "Red";
myCanvas.font = "30pt Arial";
myCanvas.fillText("Some Text", 10, 30);
但我想周围添加边框“一些文本”,对任何想法?
我可以借鉴使用下面的代码文本,如何在HTML5 Canvas的文本上添加边框?
myCanvas.fillStyle = "Red";
myCanvas.font = "30pt Arial";
myCanvas.fillText("Some Text", 10, 30);
但我想周围添加边框“一些文本”,对任何想法?
使用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);
context.strokeText('Some text', 50, 50);
context.fill();
context.stroke();
<canvas id="myc"></canvas>
什么
myCanvas.style.border = "red 1px solid";
这增加边框到画布 - 而不是在画布上绘制内的文本;我假设op想要以字母本身的形状创建边框。 – dionyziz 2012-03-24 23:20:54
我们可以使用的StrokeStyle方法来绘制文本周围或外框,和我们可以使用lineWidth方法来定义笔划线的宽度。
<script>
var canvas = document.getElementById('Canvas01');
var ctx = canvas.getContext('2d');
ctx.strokeStyle= "red"; //set the color of the stroke line
ctx.lineWidth = 3; //define the width of the stroke line
ctx.font = "italic bold 35pt Tahoma"; //set the font name and font size
ctx.strokeText("StackOverFlow",30,80); //draw the text
</script>
</body>
wao!我从未在SO中见过这样的“可执行”答案。这是一个新功能吗? – Samiron 2014-11-28 15:59:12