How can I avoid polygon edge stitching artifacts in HTML5 Canvas?

后端 未结 3 698
无人及你
无人及你 2021-01-02 18:51

I maintain parallel Flash and HTML5/Canvas renderers for the OpenHeatMap open-source project. I\'m plagued by an inconsistency in the rendering of filled polygons with fract

3条回答
  •  失恋的感觉
    2021-01-02 19:09

    This is an old question, but I had the same problem.

    I find that drawing a single line between the two polygons (or an outline around them) solves the problem (in firefox and chrome at least).

    That seems to fill the gap in chrome and firefox at least. It is sufficient to call ctx.stroke() after ctx.fill(), or draw a single line as follows:

    ctx.beginPath()
    ctx.moveTo(50.5, 0);
    ctx.lineTo(50.5, 100);
    ctx.stroke();
    

    and be sure to set the strokeStyle of course.

提交回复
热议问题