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

mc 5,061 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,371 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,961 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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.