---
title: "Convert a dashed stroke into filled shapes"
canonical: https://www.graphicsmill.com/samples/Drawing/Paths/OutlineDashedStroke_cs
product: "Graphics Mill"
source: "Drawing/Paths/OutlineDashedStroke.cs"
---

# Convert a dashed stroke into filled shapes

This sample shows how to turn the stroke of a path into an outline that can be filled, measured, or combined with other shapes, like "Outline Stroke" in vector editors. ` Path.Widen ` takes everything from a ` Pen `: its width, line caps, joins, and dash pattern, so every dash of a dashed line becomes a closed shape of its own. This is what cutting, engraving, and embroidery software needs, as it follows outlines and knows nothing about strokes. ` Path.GetArea ` then gives the area the stroke covers.

## Instruction

Use the drawing API to convert a dashed, round-capped stroke of a curved path into filled outlines with Path.Widen, then draw the outlines and the original centre line, and print the area covered by the stroke.

## Usings

```csharp
using System;
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
var centerLine = new Path();
centerLine.MoveTo(40, 150);
centerLine.CurveTo(140, 20, 240, 280, 320, 150);
centerLine.CurveTo(400, 20, 500, 280, 600, 150);

var pen = new Pen(RgbColor.Black, 30f)
{
    LineCap = LineCap.Round,
    LineJoin = LineJoin.Round,
    DashPattern = new float[] { 60, 50 },
};

// Widen changes the path in place, so work on a copy.
var outline = new Path(centerLine);
outline.Widen(pen);

using (var bitmap = new Bitmap(640, 300, PixelFormat.Format24bppRgb, RgbColor.White))
using (var graphics = bitmap.GetGraphics())
{
    graphics.FillPath(new SolidBrush(new RgbColor(255, 214, 102)), outline);
    graphics.DrawPath(new Pen(new RgbColor(90, 60, 0), 2f), outline);
    graphics.DrawPath(new Pen(RgbColor.Red, 1f), centerLine);

    bitmap.Save("OutlineDashedStroke.png");
}

Console.WriteLine("Shapes: {0}", outline.Split().Length);
Console.WriteLine("Covered area: {0:F0} square pixels", outline.GetArea());
```

## Explanation

The code:

- Builds a wavy open ` Path ` from two cubic Bezier curves with ` Path.MoveTo ` and ` Path.CurveTo `.
- Creates a 30-pixel ` Pen ` with round caps and joins and a ` DashPattern ` of 60-pixel dashes and 50-pixel gaps.
- Copies the path and calls ` Path.Widen ` on the copy, which replaces it with the outline of the stroke: one closed shape per dash.
- Fills the outlines with a light colour, strokes them with a thin dark ` Pen `, and draws the original centre line in red on top.
- Prints the number of shapes from ` Path.Split ` and the covered area from ` Path.GetArea `, then saves "OutlineDashedStroke.png".

## Tags

- [Bitmap](<https://www.graphicsmill.com/samples/tags/bitmap_md>): Working with images via the Bitmap API
- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text
- [Path](<https://www.graphicsmill.com/samples/tags/path_md>): Building, offsetting and combining vector paths

## Output

- [OutlineDashedStroke.png](<https://www.graphicsmill.com/samples/Drawing/compiled/Debug/OutlineDashedStroke_png>) (preview)
- [OutlineDashedStroke.txt](<https://www.graphicsmill.com/samples/Drawing/compiled/Debug/OutlineDashedStroke_txt>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawPath(Pen,Path)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawPath_2_77634c23.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FillPath(Brush,Path)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_FillPath_2_3cee1596.htm.md>)
- [Aurigma.GraphicsMill.Drawing.LineCap](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_LineCap.htm.md>)
- [Aurigma.GraphicsMill.Drawing.LineJoin](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_LineJoin.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Path.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.CurveTo(Single,Single,Single,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_CurveTo_6_1e65d9e1.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.GetArea](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_GetArea.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.MoveTo(Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_MoveTo_2_427c5821.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.Split](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_Split.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Path.Widen(Pen)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Path_Widen_1_00aeac81.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Pen](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Pen.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Pen.DashPattern](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Pen_DashPattern.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Pen.LineCap](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Pen_LineCap.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Pen.LineJoin](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Pen_LineJoin.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
