GraphicsPath.Flatten Method

Definition

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

Overloads

Flatten()

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

Flatten(Matrix)

Applies the specified transform and then converts each curve in this GraphicsPath into a sequence of connected line segments.

Flatten(Matrix, Single)

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

Flatten()

Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs

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

C#
public void Flatten();

Examples

For an example, see Flatten(Matrix, Single).

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Flatten(Matrix)

Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs

Applies the specified transform and then converts each curve in this GraphicsPath into a sequence of connected line segments.

C#
public void Flatten(System.Drawing.Drawing2D.Matrix? matrix);
C#
public void Flatten(System.Drawing.Drawing2D.Matrix matrix);

Parameters

matrix
Matrix

A Matrix by which to transform this GraphicsPath before flattening.

Examples

For an example, see Flatten(Matrix, Single).

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Flatten(Matrix, Single)

Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs
Source:
GraphicsPath.cs

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

C#
public void Flatten(System.Drawing.Drawing2D.Matrix? matrix, float flatness);
C#
public void Flatten(System.Drawing.Drawing2D.Matrix matrix, float flatness);

Parameters

matrix
Matrix

A Matrix by which to transform this GraphicsPath before flattening.

flatness
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.

Examples

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.

C#
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};
    myPath.AddCurve(points);
    e.Graphics.DrawPath(new Pen(Color.Black, 2), myPath);
    myPath.Flatten(translateMatrix, 10f);
    e.Graphics.DrawPath(new Pen(Color.Red, 1), myPath);
}

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10