GraphicsPath.Flatten method

Applies to: desktop apps only

The GraphicsPath::Flatten method applies a transformation to this path and converts each curve in the path to a sequence of connected lines.

Syntax

Status Flatten(
  [in]  const Matrix *matrix,
  [in]  REAL flatness
);

Parameters

matrix [in]

Type: const Matrix*

Optional. Pointer to a Matrix object that specifies the transformation to be applied to the path's data points. The default value is NULL, which specifies that no transformation is to be applied.

flatness [in]

Type: REAL

Optional. Real number that specifies the maximum error between the path and its flattened approximation. Reducing the flatness increases the number of line segments in the approximation. The default value is FlatnessDefault, which is a constant defined in Gdiplusenums.h.

Return value

Type:

Type: Status

If the method succeeds, it returns Ok, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.

Examples

The following example creates a GraphicsPath object and then adds a curve (cardinal spline), an ellipse, and a Bézier spline to the path. The code draws the path in blue, flattens the path, and then draws the flattened path in green. The call to GraphicsPath::GetPathData gets the data points stored by the flattened path. The code draws each of those points by filling a small ellipse with red.


VOID FlattenExample(HDC hdc)
{
   Graphics graphics(hdc);

   // Begin example.
   Point pts[] = {Point(20,50), 
                  Point(40,70), 
                  Point(60,10), 
                  Point(80,50)};

   GraphicsPath path;
   path.AddCurve(pts, 4);
   path.AddEllipse(20, 100, 150, 80);
   path.AddBezier(20, 200, 20, 250, 50, 210, 100, 260);

   // Draw the path before flattening.
   Pen pen(Color(255, 0, 0, 255));
   graphics.DrawPath(&pen, &path);

   path.Flatten(NULL, 8.0f);

   // Draw the flattened path.
   pen.SetColor(Color(255, 0, 255, 0));
   graphics.DrawPath(&pen, &path);

   // Get the path data from the flattened path.
   PathData pathData;
   path.GetPathData(&pathData);

   // Draw the data points of the flattened path.
   SolidBrush brush(Color(255, 255, 0, 0));
   for(INT j = 0; j < pathData.Count; ++j)
   {
      graphics.FillEllipse(
         &brush, 
         pathData.Points[j].X - 3.0f, 
         pathData.Points[j].Y - 3.0f,
         6.0f,
         6.0f);
   }
}

In the preceding example, the NULL argument passed to the GraphicsPath::Flatten method indicates no transformation should be applied to the path when it is flattened. If you want to transform the path along with flattening it, you can pass the address of a Matrix object to the GraphicsPath::Flatten method. For example, to rotate and translate the flattened path, replace the statement with the following code:


Matrix matrix;
matrix.Rotate(30.0f);
matrix.Translate(200.0f, 0.0f, MatrixOrderAppend);
path.Flatten(&matrix, 8.0f);

Requirements

Minimum supported client

Windows XP, Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Product

GDI+ 1.0

Header

Gdipluspath.h (include Gdiplus.h)

Library

Gdiplus.lib

DLL

Gdiplus.dll

See also

GraphicsPath
Matrix
Clipping with a Region
Constructing and Drawing Paths
Creating a Path Gradient
Flattening Paths
Paths

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Show: