当前位置: > 编程语言 > Delphi教程 >

再学GDI+[67]: 路径画刷(7) - 画个五角星

时间:2012-05-16 | 栏目:Delphi教程 | 点击:

本例效果图:

代码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.

您可能感兴趣的文章:

相关文章