How to prevent ugly spikes in canvas font renderin

2019-05-10 05:36发布

When I draw text in canvas, I get ugly spikes, like this:

enter image description here

Try it here: http://jsfiddle.net/48m4B/

While for example in photoshop, I get this:

enter image description here

The code is just a classic strokeText:

ctx.font = '20px Arial';
ctx.lineWidth = 15;
ctx.strokeStyle = '#fff';
ctx.strokeText('How to prevent ugly spikes?');

If it isn't possible to fix this, is there any workaround?

1条回答
forever°为你锁心
2楼-- · 2019-05-10 05:45

Try to set line join to:

ctx.lineJoin = 'round';

you can also adjust the miter limit:

ctx.miterLimit = 2;

Modified working fiddle

查看更多
登录 后发表回答