What is the widht of the round cap of a line in skiasharp?

mc 4,111 Reputation points
2021-03-19T01:08:29.633+00:00

I am using skiasharp to draw a line with round cap.which is paint.StrokeCap=SKStrokeCap.Round
and what is the round cap with? it will has a cap and how to get the with of it?

I want to draw a line which has only one cap but it will have two

So I want to draw a line which has no cap to the line's cap.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,325 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,951 Reputation points
    2021-03-19T08:10:13.877+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    What is the widht of the round cap of a line in skiasharp

    The line's width is designed by the SKPaint.StrokeWidth property. You coud define the width before drawing the line.

    I want to draw a line which has only one cap but it will have two

    It doesn't support to draw only one round cap directly, try to draw the line twice to achieve the style.
    79526-image.png
    Check the code:

       void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)  
       {  
           SKImageInfo info = args.Info;  
           SKSurface surface = args.Surface;  
           SKCanvas canvas = surface.Canvas;  
         
           canvas.Clear();  
         
           SKPaint thickLinePaint = new SKPaint  
           {  
               Style = SKPaintStyle.Stroke,  
               Color = SKColors.Orange,  
               StrokeWidth = 50  
           };  
         
           float y = textPaint.FontSpacing;  
         
           thickLinePaint.StrokeCap = SKStrokeCap.Round;  
           canvas.DrawLine(xLine1, y, 200, y, thickLinePaint);  
         
           thickLinePaint.StrokeCap = SKStrokeCap.Butt;  
           thickLinePaint.Color = SKColors.Red;  
           canvas.DrawLine(200, y, 500, y, thickLinePaint);  
       }  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful