How to prevent ugly spikes in canvas font rendering?

一世执手 提交于 2019-12-07 14:41:04

问题


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

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

While for example in photoshop, I get this:

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:


Try to set line join to:

ctx.lineJoin = 'round';

you can also adjust the miter limit:

ctx.miterLimit = 2;

Modified working fiddle



来源:https://stackoverflow.com/questions/19988099/how-to-prevent-ugly-spikes-in-canvas-font-rendering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!