Canvas.drawArc() artefacts

前端 未结 2 1385
伪装坚强ぢ
伪装坚强ぢ 2021-02-04 16:47

I draw an arc on canvas in a custom view as shown below. Paint and rectangle are defined outside of onDraw() and added in there for simpli

2条回答
  •  [愿得一人]
    2021-02-04 17:33

    I'm a StackOverflow newbie, wanted to add a comment but could not (having insufficient points) so had to put my comment in an answer !

    One strange thing is that the arc overshoots the specified end position with a straight vertical line at the outer side. The inner end point seems to be ok. Of course this and the other mess of lines does not tell what causes the problem.

    It seems to appear when the end angle is at exactly a multiple of 90 degrees. This looks like a numeric calculation bug, float round-off issue etc. @kcoppock remarked that 314.98f already circumvents the bug. Probably any value other than exactly 315.0f may do the trick.

    If code optimization is involved (attempts to draw the arc in as little line segments as possible) another trick that may work is to simplify the arc by cutting it into pieces -> use multiple drawArc calls that each span a certain maximum angle. Candidates are 30, 45, 90 and 180 degrees. Remains to be seen if the joints will be invisible...

    It's a bit of a long shot, hope any of these suggestions might work.

提交回复
热议问题