سؤال

يمكنني رسم النص باستخدام الكود أدناه،

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 طريقة لرسم الحدود حول النص أو المخطط التفصيلي، ويمكننا استخدامها عرض الخط طريقة لتحديد عرض خط السكتة الدماغية.

 <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