Drawing text with an outer stroke with HTML5's canvas

前端 未结 4 697
灰色年华
灰色年华 2020-12-30 01:57

I\'m currently using HTML5\'s canvas to render a number of strings using the fillText method. This works fine, but I\'d also like to give each string a 1px black outer strok

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-30 02:32

    Simon's answer is a good solution, yet it may have mitering glitches in some cases, especially with capital 'M', 'V', & 'W':

    drawStroked("MVW", 50, 150);
    

    http://jsfiddle.net/hwG42/1/

    In this case, it's best to utilize:

    ctx.miterLimit=2;
    

    http://jsfiddle.net/hwG42/3/

    Best of luck!

提交回复
热议问题