AddColorStop Method
Class TCanvasLinearGradient, Class TCanvasRadialGradient
procedure AddColorStop(Stop: Double; Color: TCanvasColor);
Note:
You can call the AddColorStop method multiple times to change a gradient. If you omit this method for gradient objects, the gradient will not be visible. You need to create at least one color stop to have a visible gradient.
Parameter Values
A value between 0.0 and 1.0 that represents the position between start and end in a gradient.
A color value to display at the stop position.
Examples:
Define a gradient that goes from black to white, as the fill style for the rectangle:
var
Gradient: TCanvasLinearGradient;
Gradient := Canvas.CreateLinearGradient(0,0,150,0);
Gradient.AddColorStop(0,clBlack);
Gradient.AddColorStop(1,clWhite);
Canvas.FillStyle := Gradient;
Canvas.FillRect(0,0,150,100);
Define a gradient with multiple AddColorStop methods:
var
Gradient: TCanvasLinearGradient;
Gradient := Canvas.CreateLinearGradient(0,0,150,0);
Gradient.AddColorStop(0, clWhite);
Gradient.AddColorStop(0.3, clMagenta);
Gradient.AddColorStop(0.5, clBlue);
Gradient.AddColorStop(0.6, clGreen);
Gradient.AddColorStop(0.8, clYellow);
Gradient.AddColorStop(1, clWhite);
Canvas.FillStyle := Gradient;
Canvas.FillRect(0,0,150,100);
Draw a rectangle and fill with a radial/circular gradient:
var
Gradient: TCanvasRadialGradient;
Gradient := Canvas.CreateRadialGradient(75,50,5,70,60,100);
Gradient.AddColorStop(0,clRed);
Gradient.AddColorStop(1,clWhite);
Canvas.FillStyle := Gradient;
Canvas.FillRect(0,0,150,100);