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)

Syntax

Visual Basic (Declaration)
Public Sub Flatten ( _
    matrix As Matrix, _
    flatness As Single _
)
Visual Basic (Usage)
Dim instance As GraphicsPath
Dim matrix As Matrix
Dim flatness As Single

instance.Flatten(matrix, flatness)
C#
public void Flatten (
    Matrix matrix,
    float flatness
)
C++
public:
void Flatten (
    Matrix^ matrix, 
    float flatness
)
J#
public void Flatten (
    Matrix matrix, 
    float flatness
)
JScript
public function Flatten (
    matrix : Matrix, 
    flatness : float
)
XAML
Not applicable.

Parameters

matrix

A Matrix by which to transform this GraphicsPath before flattening.

flatness

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.

Example

The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, 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.

Visual Basic
Public Sub FlattenExample(ByVal e As PaintEventArgs)
    Dim myPath As New GraphicsPath
    Dim translateMatrix As New Matrix
    translateMatrix.Translate(0, 10)
    Dim point1 As New Point(20, 100)
    Dim point2 As New Point(70, 10)
    Dim point3 As New Point(130, 200)
    Dim point4 As New Point(180, 100)
    Dim points As Point() = {point1, point2, point3, point4}
    myPath.AddCurve(points)
    e.Graphics.DrawPath(New Pen(Color.Black, 2), myPath)
    myPath.Flatten(translateMatrix, 10.0F)
    e.Graphics.DrawPath(New Pen(Color.Red, 1), myPath)
End Sub
'FlattenExample
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);
}
C++
private:
   void FlattenExample( PaintEventArgs^ e )
   {
      GraphicsPath^ myPath = gcnew GraphicsPath;
      Matrix^ translateMatrix = gcnew Matrix;
      translateMatrix->Translate( 0, 10 );
      Point point1 = Point(20,100);
      Point point2 = Point(70,10);
      Point point3 = Point(130,200);
      Point point4 = Point(180,100);
      array<Point>^ points = {point1,point2,point3,point4};
      myPath->AddCurve( points );
      e->Graphics->DrawPath( gcnew Pen( Color::Black,2.0f ), myPath );
      myPath->Flatten( translateMatrix, 10.0f );
      e->Graphics->DrawPath( gcnew Pen( Color::Red,1.0f ), myPath );
   }
J#
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.get_Graphics().DrawPath(new Pen(Color.get_Black(), 2), myPath);
    myPath.Flatten(translateMatrix, 10);
    e.get_Graphics().DrawPath(new Pen(Color.get_Red(), 1), myPath);
} //FlattenExample
Platforms

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
See Also

Tags :


Community Content

CChalom
Visual FoxPro code:

Converted code from .NET to GdiPlusX VFP-X Foundation Classes
http://www.codeplex.com/VFPX/Wiki/View.aspx?title=GDIPlusX&referringTitle=Home

 _SCREEN.AddProperty("System", NEWOBJECT("xfcSystem", LOCFILE("system.vcx","vcx"))) 
 WITH _SCREEN.System.Drawing
 * Retrieve the graphics object.
* Initialize the graphics object to be able to draw in the _screen
LOCAL loScreenGfx AS xfcGraphics
loScreenGfx = .Graphics.FromHwnd(_Screen.HWnd)
 LOCAL loMyPath as xfcGraphicsPath
loMyPath = .Drawing2D.GraphicsPath.New()
 LOCAL loTranslateMatrix as xfcMatrix
loTranslateMatrix = .Drawing2D.Matrix.New()
loTranslateMatrix.Translate(0, 10)
 LOCAL ARRAY laPoints(4)
laPoints(1) = .Point.New(20, 100)
laPoints(2) = .Point.New(70, 100)
laPoints(3) = .Point.New(130, 200)
laPoints(4) = .Point.New(180, 100)
 loMyPath.AddCurve(@laPoints)
 loScreenGfx.DrawPath(.Pen.New(.Color.Black, 2), loMyPath)
loMyPath.Flatten(loTranslateMatrix, 10)
 loScreenGfx.DrawPath(.Pen.New(.Color.Red, 1), loMyPath)
 ENDWITH 
RETURN
Tags :

Page view tracker