再学 GDI+[67]: 路径画刷(7) - 画个五角星
2008-06-28 21:41
405 查看
本例效果图:
代码1:
代码2:
窗体文件:
代码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.
代码2:
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..9] of TGPPoint; radian: Single; i,num: Integer; rx: Single; begin for i := 0 to 9 do begin rx := r; if Odd(i) then rx := r * (1- (Sqrt(5)-1)/2); {(Sqrt(5)-1)/2 是黄金分割点, 约为 0.618} radian := i * (360/10) * (Pi/180); pts[i].X := pt.X + Round(Sin(radian) * rx); pts[i].Y := pt.Y - Round(Cos(radian) * rx); 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.
窗体文件:
object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 238 ClientWidth = 259 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
相关文章推荐
- 再学 GDI+[62]: 路径画刷(2) - SetCenterPoint、GetCenterPoint
- 再学 GDI+[69]: 路径画刷(9) - SetInterpolationColors 与 SetSurroundColors 的区别
- 再学 GDI+[63]: 路径画刷(3) - SetFocusScales、GetFocusScales
- 再学 GDI+[70]: 路径画刷(10) - SetBlend
- 再学 GDI+[71]: 路径画刷(11) - RotateTransform、ScaleTransform 等变换
- 再学 GDI+[64]: 路径画刷(4) - 还是 SetCenterColor、SetSurroundColors
- 再学 GDI+[65]: 路径画刷(5) - SetGammaCorrection
- GDI+ 学习记录(11): 路径渐变画刷 - PathGradientBrush
- 再学 GDI+[61]: 路径画刷(1) - SetCenterColor、SetSurroundColors
- 再学 GDI+[66]: 路径画刷(6) - SetInterpolationColors、GetRectangle
- GDI+学习记录(15)-路径渐变画刷
- 再学 GDI+[68]: 路径画刷(8) - SetBlendTriangularShaped、SetBlendBellShape
- GDI+ 学习记录(11) 路径渐变画刷 - PathGradientBrush
- 再学 GDI+[47]: 路径 - CloseFigure
- 再学 GDI+[50]: 路径 - GetPathPoints、GetPathTypes、TPathData、GetPathData
- 再学 GDI+[54]: 路径 - Transform
- 再学 GDI+[59]: 路径 - TGPGraphicsPathIterator
- (转载)GDI+画刷Brush
- GDI+[58]: 路径 - 保存与读取路径数据
- EularProject 67: 三角形数字矩阵的最大路径