Como adicionar uma borda em texto HTML5 Canvas'?
-
07-07-2019 - |
Pergunta
Eu posso desenhar texto usando o código abaixo,
myCanvas.fillStyle = "Red";
myCanvas.font = "30pt Arial";
myCanvas.fillText("Some Text", 10, 30);
Mas eu quero adicionar uma borda ao redor "Alguns texto", todas as idéias sobre isso?
Solução
Use strokeText()
eo strokeStyle.
por exemplo:
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>
Outras dicas
Podemos usar strokeStyle método para desenhar borda ao redor do texto ou esboço, e podemos usar lineWidth para definir a largura da linha de acidente vascular cerebral.
<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>
E
myCanvas.style.border = "red 1px solid";
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow