question

6666666 avatar image
0 Votes"
6666666 asked JarvanZhang-MSFT edited

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

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.

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT edited

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.



image.png (4.0 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am asking the cap width not the line width.

which means the ( width of cap line - the width of butt line ) / 2

0 Votes 0 ·

For SKStrokeCap.Round, the contour adds a semi-circle extension at the begin and end. The result of (width of cap line - the width of butt line) / 2 is equals to half of the SKPaint.StrokeWidth. SKStrokeCap.Square adds a half square extension, the calculation result is also half of the SKPaint.StrokeWidth.

Check the document:
https://docs.microsoft.com/en-us/dotnet/api/skiasharp.skstrokecap?view=skiasharp-2.80.2

0 Votes 0 ·