delphi 画五角星
最近开发一个预约功能,里面有个蛋糕甜度的选择 ,是用星号标识甜度,如

//用gdi画,也可以用 两个图标来回切换 uses GDIPOBJ, GDIPAPI; //画星星 procedure DrawStart(vcanvas: TCanvas;visfill: boolean = false); const pt: TPoint = (X:20; Y:20); r = 10; colors: array[0..0] of TGPColor = (clWhite); 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; vcanvas.FillRect(vcanvas.ClipRect); g := TGPGraphics.Create(vcanvas.Handle); path := TGPGraphicsPath.Create; path.AddPolygon(PGPPoint(@pts), Length(pts)); pb:= TGPPathGradientBrush.Create(path); num := Length(colors); pb.SetSurroundColors(@colors, num); pb.SetCenterColor(aclBlack); {描个边} p := TGPPen.Create(aclBlack); g.SetSmoothingMode(SmoothingModeAntiAlias); g.DrawPath(p, path); if visfill then begin for I := 0 to 10 do g.FillPath(pb, path); end; pb.Free; path.Free; p.Free; g.Free; end; ///使用 if img1.Tag = 0 then begin DrawStart(img1.Canvas,true); img1.Tag := 1; end else begin DrawStart(img1.Canvas,false); img1.Tag := 0; end;
好不容易活着

浙公网安备 33010602011771号