Home  |  Delphi .net Home  |  System.Drawing.Graphics  |  DrawBeziers Method
  
DrawBeziers  
Method  
Draws a set of bezier curves on the current graphics canvas
Graphics Class
System.Drawing NameSpace
NotCF1.  Procedure DrawBeziers ( Pen : System.Drawing.Pen; Points : Array of Point ) ;
NotCF2.  Procedure DrawBeziers ( Pen : System.Drawing.Pen; Points : Array of PointF ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
A Bezier curve is fundamental to representation of curves in graphical applications. The curve start and end points are defined, along with the same for a controlling line. A smooth curve is then drawn from the curve start point to the end, and moving close to, and parallel to the line at its centre point.
 
The DrawBeziers method draws a set of connected beziers - the end point of the first curve being the start point of the next and so on. So the number of points in the array should be 4 + (n*3) where the number of curves required is n-1.
 
The curve starts along the line between the curve and line start points. Likewise, the curve ends on the line between the curve and line end points.
 
The Pen object determines the style of line, its endcaps, its width and colour. By default, specifying a new pen just by colour will create a 1 pixel width line style. Endcaps allowed are defined by the System.Drawing.Drawing2D.LineCap enumeration :
 
AnchorMask
ArrowAnchor
Custom
DiamondAnchor
Flat
NoAnchor
Round
RoundAnchor
Square
SquareAnchor
Triangle
Notes
The implementation that Microsoft have adopted appears to differ from that which is familiar in graphic art packages. Namely that the curve does not actually touch the controlling line at its centre. The MSDN documentation does not describe the algorithm used.
Microsoft MSDN Links
System.Drawing
System.Drawing.Graphics
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
Draw a pair of connected bezier curves, showing the controlling lines
// Full Unit code.
// -------------------------------------------------------------
// Create a new WinForm application, double click the form to
// create an OnLoad event, and then replace the WinForm unit
// with this text.
 
unit WinForm;
 
interface
 
uses
  System.Drawing, System.Collections, System.ComponentModel,
System.Windows.Forms, System.Data;
 
type
  TWinForm = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    ///
    /// Required designer variable.
    ///

    Components: System.ComponentModel.Container;
    ///
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    ///

    procedure InitializeComponent;
    procedure TWinForm_Load(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict protected
    ///
    /// Clean up any resources being used.
    ///

    procedure Dispose(Disposing: Boolean); override;
  private
    { Private Declarations }
  public
    constructor Create;
  end;
 
  [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))]
 
implementation
 
{$REGION 'Windows Form Designer generated code'}
///
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
///

 
 
procedure TWinForm.InitializeComponent;
begin
  //
  // TWinForm
  //
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13);
  Self.ClientSize := System.Drawing.Size.Create(292, 266);
  Self.Name := 'TWinForm';
  Self.Text := 'WinForm';
  Include(Self.Load, Self.TWinForm_Load);
end;
{$ENDREGION}
 
procedure TWinForm.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;
 
constructor TWinForm.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;
 
procedure TWinForm.TWinForm_Load(sender: System.Object; e: System.EventArgs);
procedure TWinForm.TWinForm_Paint(sender: System.Object;
                                  e: System.Windows.Forms.PaintEventArgs);
var
  myPen  : System.Drawing.Pen;
  points : Array[1..7] of System.Drawing.Point;
begin
  // Create the pen object
  myPen := System.Drawing.Pen.Create(Color.Red, 1);

  // Establish the 7 points to create two bezier curves :
  // 1. 1st Curve start
  // 2. 1st Controlling tangential line start
  // 3. 1st Controlling tangential line end
  // 4. 1st Curve end
  // 5. 2nd Controlling tangential line start
  // 6. 2nd Controlling tangential line end
  // 7. 2nd Curve end
  points[1] := Point.Create( 5,  5);
  points[2] := Point.Create(10, 15);
  points[3] := Point.Create(20, 15);
  points[4] := Point.Create(25,  5);
  points[5] := Point.Create(60,  5);
  points[6] := Point.Create(60, 15);
  points[7] := Point.Create(45, 15);

  // A 1 pixel wide red bezier
  e.Graphics.DrawBeziers(myPen, points);

  // Now draw the controlling lines
  myPen.Color := Color.blue;
  e.Graphics.DrawLine(myPen, points[2], points[3]);
  e.Graphics.DrawLine(myPen, points[5], points[6]);
end;
 
end.
Hide full unit code
   
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author