Forum General

SkiaSharp DrawPoints with Polygon Mode Fill Paint

jcarasickjcarasick Member ✭✭

I am trying to draw a polygon with a Fill color using the DrawPoints method and SKPointMode.Polygon style. It seems to only draw the outline with no fill. Is there anyway to do this? Seems much more performant over the DrawPath method.

        var color = SKColors.Black;
        if (c != null)
        {
            color = new SKColor((byte)c.R, (byte)c.G, (byte)c.B, (byte)c.A);
        }
        var fillPaint = new SKPaint
        {
            Style = SKPaintStyle.Fill,
            Color = color
        };

    canvas.DrawPoints(SKPointMode.Polygon, points, fillPaint);

Thanks!

Answers

  • Antoine_BAntoine_B Member ✭✭

    +1

    Do you find a solution @jcarasick ?

  • jcarasickjcarasick Member ✭✭

    I didn't. I am still using the draw path method. one route i took which helped was creating one large path for many polygons (think multipart polygon) vs. many paths (one path per polygon).

    something like

                     var path = new SKPath();
                     foreach (var points in polygonlist)
                     {
                            path.MoveTo(points.First());
                            for (var i = 1; i < points.Count; i++)
                            {
                                path.LineTo(points[i]);
                            }
                      }
    
                  //render polygons
                      canvas.DrawPath(path, fillPaint);
                      canvas.DrawPath(path, outlinePaint);
    
  • Antoine_BAntoine_B Member ✭✭

    Okay, thank you for your answer.
    I still think that a solution must exist :smile:

  • RolandHuhnRolandHuhn USMember ✭✭

    Maybe a bit late, but here is a solution:

    You need to call Close() to fill the polygon.

    https://stackoverflow.com/questions/45311585/skiasharp-does-not-fill-triangle-with-strokeandfill

Sign In or Register to comment.