Drawing a Polygon with One Color for Stroke, and a Different One for Fill

Drawing a polygon with one color for stroke, and a different one for fill?

You can use

CGContextDrawPath(context, kCGPathFillStroke);

instead of

CGContextFillPath(context);
CGContextStrokePath(context);

The problem is that both CGContextFillPath() and CGContextStrokePath(context)
clear the current path, so that only the first operation succeeds, and the second
operation draws nothing. CGContextDrawPath() combines fill and stroke without
clearing the path in between.

Drawing WPF Polygon with a stroke in solid color or transparent around

Starting from @Clemens indication, I elaborate a solution with a series of transformation, without any geometric calculus. Less or more the solution is here, I will try to apply to my context, but in the end is:

    <Path MouseLeftButtonUp="PathPolyline_MouseLeftButtonUp"
StrokeThickness="0" Stroke="Transparent" Fill="Gold" ClipToBounds="False">
<Path.Data>
<PathGeometry FillRule="EvenOdd" >
<PathFigure StartPoint="0,0" IsClosed="True">
<PolyLineSegment Points="50,50 0,80"/>
</PathFigure>
</PathGeometry>
</Path.Data>
</Path>

and elaboration in C# code will do something as:

private void PathPolyline_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Brush brush = Brushes.Black;
Pen pen = new Pen(brush, 20.0); //thickness double than wanted measure: 20 to reduce 10
//
Path path = sender as Path;
PathGeometry pg = path.Data as PathGeometry;
PathGeometry pg2 = pg.GetWidenedPathGeometry(pen);
//
Transform tr = Transform.Identity;
PathGeometry pg324 = Geometry.Combine(pg, pg2, GeometryCombineMode.Intersect, tr);
pg.AddGeometry(pg324);
}

Stylize polygon stroke and fill differently?

The polygon layer only renders the fill area. To draw an outline of a polygon, use a line layer connected to the same data source. See the second example in the documentation: https://learn.microsoft.com/en-us/azure/azure-maps/map-add-shape

Different stroke of polygon SVG

Draw 2 paths. Make one path the red parts of the polygon and the other the black.

Is it possible to draw object with outline and fill at the same time?

The answer is: you can't. Both color properties (Color and ColorF) of SKPaint set the same SKColorF value internally (Color being converted into ColorF). The 'F' in ColorF indicates the RGBA values are stored as floats instead of bytes.



Related Topics



Leave a reply



Submit