function FlattenCBezier(const pt1, pt2, pt3, pt4: TPointD): TPathD; overload;
function FlattenCBezier(const pts: TPathD): TPathD; overload;
function FlattenCBezier(const pts: TPathsD): TPathsD; overload;
A Cubic Bezier consists of four points, two end points and two control points that all together define a curved path. This function converts these cubic beziers into normal paths, where the curved path is defined by series of sometimes very short straight edges.
uses Img32, Img32.Fmt.PNG, Img32.vector, Img32.Draw;
...
var
img: TImage32;
path, path2: TPathD;
rec: TRect;
begin
img := TImage32.Create(256,256);
rec := img.Bounds;
Windows.InflateRect(rec, -10,-10);
// flatten a cubic bezier defined by 4 corners of rec
with rec do
path := FlattenCBezier(PointD(left, top), PointD(left, bottom),
PointD(right, bottom), PointD(right, top));
//draw the bezier curve
DrawLine(img, path, 10, clMaroon32, esRound);
img.SaveToFile('line2.png');
img.Free;
end;
FlattenCSpline, FlattenQBezier
Copyright ©2010-2023 Angus Johnson - Image32 4.8 - Help file built on 16 Apr 2025