Вопрос

Я могу нарисовать текст, используя приведенный ниже код,

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>

Другие советы

Мы можем использовать метод 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>

Как насчет

myCanvas.style.border = "red 1px solid";
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top