Drawing a Bezier Curve using Firemonkey

firemonkey

Solution

The following code can be used to draw a simple Bezier curve using Firemonkey XE6. Create a new Firemonkey application, and in the Form OnPaint handler include the code:

procedure TForm1.FormPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
var path : TPathData;
begin
  path := TPathData.Create;
  try
    path.MoveTo(TPointF.Create (10,100));
    path.CurveTo (TPointF.Create(100,10),TPointF.Create(150,150),
                  TPointF.Create(200,100));
    Canvas.Stroke.Thickness := 2;
    Canvas.Stroke.Color := claRed;
    Canvas.BeginScene;
    Canvas.DrawPath(path, 1.0);
    Canvas.EndScene;
  finally
    path.Free;
  end;
end;

The CurveTo takes three arguments, the two Bezier control points and the final point. MoveTo provides the starting point.

Problem

How do I draw a Bezier curve using Firemonkey (XE6)? The documentation is currently a little sparse in the XE6 wiki.

Original source