CGPathDrawingMode CGPathDrawingMode Enum

Definition

Drawing mode.

public enum CGPathDrawingMode
type CGPathDrawingMode = 
Inheritance
CGPathDrawingModeCGPathDrawingMode

Fields

EOFill EOFill 1

Fills the path using the even-odd rule.

EOFillStroke EOFillStroke 4

Fills and strokes the path using the even-odd rule.

Fill Fill 0

Fills the path using the non-zero winding rule.

FillStroke FillStroke 3

Fills and strokes the path using the non-zero winding rule.

Stroke Stroke 2

Strokes the path.

Remarks

This enumeration allows the application developer to choose between showing the fill, stroke, or both of a path. Additionally, it allows the developer to choose whether to use the Core Graphics standing "non-zero winding rule" fill mode or the "even-odd rule" fill mode.

Both the "non-zero winding rule" and the "even-odd rule" decide whether to fill a pixel by considering a line drawn from the point to outside the path.

The “non-zero winding rule” mode does not fill the pixel if the path crosses that line clockwise and counterclockwise an equal number of times. If the count of clockwise versus counterclockwise crossings is non-zero, the point is considered inside the path and is filled. As the following illustration shows, this makes path direction an important consideration.

The “even-odd” rule fills a pixel if the number of paths crossed is odd. It does not take the direction of the path into account.

The following example shows a more complex situation. The top path is drawn with the "even-odd rule" (EOFillStroke) while the bottom is filled with the "non-zero winding rule" (FillStroke). In both cases, the path is both stroked in red and filled in green.


 public override void Draw (RectangleF rect)
{
    base.Draw (rect);

    using (var ctxt = UIGraphics.GetCurrentContext ()) {
        ctxt.ScaleCTM (1, -1);
        ctxt.TranslateCTM (0, -Bounds.Height);
    DrawPathWithWindingMode (ctxt, Bounds.Height / 2, CGPathDrawingMode.EOFillStroke);
      DrawPathWithWindingMode (ctxt, 0, CGPathDrawingMode.FillStroke);
        }
}

void DrawPathWithWindingMode (CGContext ctxt, float yOffset, CGPathDrawingMode mode)
{
    var points = new PointF[] {
        new PointF (50, 50),
        new PointF (200, 50),
        new PointF (200, 100),
        new PointF (50, 100),
        new PointF (50, 50),
        new PointF (150, 50),
        new PointF (150, 150),
        new PointF (100, 150),
        new PointF (100, 25)
    };
    points = points.Select (pt => new PointF(pt.X, pt.Y += yOffset)).ToArray();
    ctxt.SetStrokeColor (UIColor.Red.CGColor);
    ctxt.SetFillColor (UIColor.Green.CGColor);
    ctxt.MoveTo (points [0].X, points [0].Y);
    for (var i = 1; i < points.Length; i++) {
        ctxt.AddLineToPoint (points [i].X, points [i].Y);
    }
    ctxt.DrawPath (mode);
}         

Applies to