The difference between setinterpolationcolors and setsurroundcolors
This example effect chart:
Code files:Unit Unit1;
Interface
Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Comctrls, Stdctrls, Extctrls;
Type
TForm1 = Class (Tform)
Procedure Formpaint (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$R *.DFM}
Uses Gdipobj, GDIPAPI;
Procedure Tform1.formpaint (Sender:tobject);
Const
COLORS:ARRAY[0..3] of Tgpcolor = (aclred, Aclyellow, Aclgreen, Aclblue);
POS:ARRAY[0..3] of single = (0.0, 0.2, 0.6, 1.0); {As if data must be 0 and 1} at both ends
Var
G:tgpgraphics;
Path:tgpgraphicspath;
Pb:tgppathgradientbrush;
Num:integer;
Pts:array of Tgppoint;
Begin
G: = Tgpgraphics.create (Canvas.handle);
Path: = Tgpgraphicspath.create;
{Create an ellipse path and create a path based on the path brush, then set the color with setinterpolationcolors}
Path. AddEllipse (Makerect (10,10,150,150));
PB: = tgppathgradientbrush.create (path);
Pb. Setinterpolationcolors (@colors, @pos, Length (POS));
G.fillpath (Pb, Path);
{Create path brush based on ellipse path, then set color with setsurroundcolors}
Pb. Free;
PB: = tgppathgradientbrush.create (path);
Num: = Length (POS);
Pb. Setsurroundcolors (@colors, num);
G.translatetransform (160, 0);
G.fillpath (Pb, Path);
{Create a path brush based on an array of points extracted from the ellipse path, and then set the color with setsurroundcolors}
SetLength (pts, path. Getpointcount);
Path. Getpathpoints (Pgppoint (pts), Length (pts));
Pb. Free;
PB: = Tgppathgradientbrush.create (Pgppoint (pts), Length (pts));
Pb. Setcentercolor (Aclwhite); {At this point the center will default to black, I want the White}
Num: = Length (colors);
Pb. Setsurroundcolors (@colors, num);
G.translatetransform (160, 0);
G.fillpath (Pb, Path);
{Create a path brush based on an array of points extracted from the ellipse path, and then set the color with setinterpolationcolors}
SetLength (pts, path. Getpointcount);
Path. Getpathpoints (Pgppoint (pts), Length (pts));
Pb. Free;
PB: = Tgppathgradientbrush.create (Pgppoint (pts), Length (pts));
Pb. Setcentercolor (Aclwhite); {No Center color required here}
Num: = Length (colors);
Pb. Setinterpolationcolors (@colors, @pos, Length (POS));
G.translatetransform (160, 0);
G.fillpath (Pb, Path);
Pb. Free;
Path. Free;
G.free;
End
End.
Form file:object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 169
ClientWidth = 649
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
OnPaint = FormPaint
PixelsPerInch = 96
TextHeight = 13
end