This documentation is archived and is not being maintained.

GraphicsPath.Flatten Method (Matrix, Single)

Converts each curve in this GraphicsPath into a sequence of connected line segments.

Namespace:  System.Drawing.Drawing2D
Assembly:  System.Drawing (in System.Drawing.dll)

public void Flatten(
	Matrix matrix,
	float flatness


Type: System.Drawing.Drawing2D.Matrix
A Matrix by which to transform this GraphicsPath before flattening.
Type: System.Single
Specifies the maximum permitted error between the curve and its flattened approximation. A value of 0.25 is the default. Reducing the flatness value will increase the number of line segments in the approximation.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, an OnPaint event object. The code performs the following actions:

  • Creates a graphics path and a translation matrix.

  • Adds a curve to the path using four points.

  • Draws the path (curve) to the screen, using a black pen.

  • Shifts the curve down 10 pixels and flattens it.

  • Draws the curve to the screen using, a red pen.

Notice that the red curve has flattened lines connecting the points.

private void FlattenExample(PaintEventArgs e)
    GraphicsPath myPath = new GraphicsPath();
    Matrix translateMatrix = new Matrix();
    translateMatrix.Translate(0, 10);
    Point point1 = new Point(20, 100);
    Point point2 = new Point(70, 10);
    Point point3 = new Point(130, 200);
    Point point4 = new Point(180, 100);
    Point[] points = {point1, point2, point3, point4};
    e.Graphics.DrawPath(new Pen(Color.Black, 2), myPath);
    myPath.Flatten(translateMatrix, 10f);
    e.Graphics.DrawPath(new Pen(Color.Red, 1), myPath);

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.