本例效果图:
代码1:unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormPaint(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses GDIPOBJ, GDIPAPI;
procedure TForm1.FormPaint(Sender: TObject);
const
pt: TPoint = (X:130; Y:130);
r = 120;
colors: array[0..0] of TGPColor = (aclRed);
var
g: TGPGraphics;
p: TGPPen;
path: TGPGraphicsPath;
pb: TGPPathGradientBrush;
pts: array[0..4] of TGPPoint;
radian: Single;
i,num: Integer;
begin
for i := 0 to 4 do
begin
radian := i * (360*2/5) * (Pi/180);
pts[i].X := pt.X + Round(Sin(radian) * r);
pts[i].Y := pt.Y - Round(Cos(radian) * r);
end;
g := TGPGraphics.Create(Canvas.Handle);
path := TGPGraphicsPath.Create;
path.AddPolygon(PGPPoint(@pts), Length(pts));
pb:= TGPPathGradientBrush.Create(path);
num := Length(colors);
pb.SetSurroundColors(@colors, num);
pb.SetCenterColor(aclYellow);
{描个边}
p := TGPPen.Create(aclYellow);
g.SetSmoothingMode(SmoothingModeAntiAlias);
g.DrawPath(p, path);
g.FillPath(pb, path);
pb.Free;
path.Free;
p.Free;
g.Free;
end;
end.