Skip to content

绘制空星星时,空星星中间hole出现黑色边线的问题 #4

Description

@oukanggui

issue
大神,你好,我今天在使用贵控件时,当把星星前景和背景颜色分别设置为如下颜色值时starForegroundColor=0xffff5400,starBackgroundColor = 0x99333333,出现空星星中间圆部分出现黑色边线,初步认为绘制星星中部算法可能有问题:
private void drawSolidStar(StarModel star, Canvas canvas, int fillColor) { paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setColor(fillColor); paint.setPathEffect(pathEffect); VertexF prev = star.getVertex(1); Path path = new Path(); for (int i = 0; i < 5; i++) { path.rewind(); path.moveTo(prev.x, prev.y); VertexF next = prev.next; path.lineTo(next.x, next.y); path.lineTo(next.next.x, next.next.y); path.lineTo(next.next.x, next.next.y); canvas.drawPath(path, paint); prev = next.next; } // fill the middle hole. use +1.0 +1.5 because the path-API will leave 1px gap. path.rewind(); prev = star.getVertex(1); path.moveTo(prev.x - 1f, prev.y - 1f); prev = prev.next.next; path.lineTo(prev.x + 1.5f, prev.y - 0.5f); prev = prev.next.next; path.lineTo(prev.x + 1.5f, prev.y + 1f); prev = prev.next.next; path.lineTo(prev.x, prev.y + 1f); prev = prev.next.next; path.lineTo(prev.x - 1f, prev.y + 1f); paint.setPathEffect(null); canvas.drawPath(path, paint); }

在细看代码时,收获很大,也有点疑惑,就是为什么需要分两次画填充满星星?我考虑改为一次path填充画完时,发现没有了该现象,分两次画填充时,绘制星星中部路径算法是否存在问题?代码如下所示:
private void drawSolidStar(StarModel star, Canvas canvas, int fillColor) { paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setColor(fillColor); paint.setPathEffect(pathEffect); VertexF prev = star.getVertex(1); Path path = new Path(); path.moveTo(prev.x, prev.y); for (int i = 0; i < 5; i++) { VertexF next = prev.next; path.lineTo(next.x, next.y); path.lineTo(next.next.x, next.next.y); path.lineTo(next.next.x, next.next.y); prev = next.next; } canvas.drawPath(path, paint); }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions