Notice that the SkiaSharp namespace declarations are a little different because the SkiaSharp namespace is needed to reference the members of the SKPointMode and SKStrokeCap enumerations. The MultipleLinesPage.xaml file instantiates two Picker views that let you select a member of the SKPointMode enumeration and a member of the SKStrokeCap enumeration: The Multiple Lines page demonstrates this method. Polygon to connect all consecutive points.The points parameter is an array of SKPoint values and mode is a member of the SKPointMode enumeration, which has three members: The SKCanvas class also includes another method for drawing multiple lines that is somewhat peculiar: DrawPoints (SKPointMode mode, points, paint) This extension becomes important when it's necessary to determine the dimensions of a rendered graphics object. This second line is intended to illustrate the geometric start and end of the line independent of the line thickness and a stroke cap:Īs you can see, the Square and Round stroke caps effectively extend the length of the line by half the stroke width at the beginning of the line and again at the end. This page defines a PaintSurface event handler that loops through the three members of the SKStrokeCap enumeration, displaying both the name of the enumeration member and drawing a line using that stroke cap: void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)įoreach (SKStrokeCap strokeCap in Enum.GetValues(typeof(SKStrokeCap)))Ĭanvas.DrawText(strokeCap.ToString(), xText, y, textPaint) Ĭanvas.DrawLine(xLine1, y, xLine2, y, thickLinePaint) Ĭanvas.DrawLine(xLine1, y, xLine2, y, thinLinePaint) įor each member of the SKStrokeCap enumeration, the handler draws two lines, one with a stroke thickness of 50 pixels and another line positioned on top with a stroke thickness of two pixels. The SkiaSharp Lines and Paths section of the SkiaSharpFormsDemos program begins with a page titled Stroke Caps based on the StrokeCapsPage class. These are best illustrated with a sample program. You set the StrokeCap property of the SKPaint object to one of the following members of the SKStrokeCap enumeration: The word "cap" in this context refers to a kind of hat - something that sits on the end of the line. The appearance of the starts and ends of lines is called a line cap or, in Skia, a stroke cap. But once you start drawing lines of a sizable thickness, that raises another issue: How should the starts and ends of these thick lines be rendered? This appears very thin on high-resolution devices such as phones, so you'll probably want to set the StrokeWidth to a larger value. The appearance of the end of the line is called the stroke cap:įor drawing single lines, SKCanvas defines a simple DrawLine method whose arguments indicate the starting and ending coordinates of the line with an SKPaint object: canvas.DrawLine (x0, y0, x1, y1, paint) īy default, the StrokeWidth property of a newly instantiated SKPaint object is 0, which has the same effect as a value of 1 in rendering a line of one pixel in thickness. As these lines become wider, the appearance of the ends of the lines also becomes important. Even when drawing single lines, however, it's often necessary to give the lines a particular stroke width. In SkiaSharp, rendering a single line is very different from rendering a series of connected straight lines. Learn how to use SkiaSharp to draw lines with different stroke caps
0 Comments
Leave a Reply. |