zoukankan      html  css  js  c++  java
  • GDI+ 学习记录(11): 路径渐变画刷 PathGradientBrush

    //路径渐变画刷
    var
      g: TGPGraphics;
      path: TGPGraphicsPath;
      pb: TGPPathGradientBrush; {声明渐变画刷}
      num: Integer;
    const
      colors: array[0..0] of TGPColor = (aclAqua);
    begin
      g := TGPGraphics.Create(Canvas.Handle);
      path := TGPGraphicsPath.Create;
      path.AddEllipse(0,0,166,88);
    
      pb := TGPPathGradientBrush.Create(path);   {建立渐变画刷}
      pb.SetCenterColor(MakeColor(255,0,0,255)); {中心颜色}
    
      num := 1;
      pb.SetSurroundColors(@colors, num); {周围的颜色}
      {第二个参数, 不能用常数代替; 它好像是第一个数组参数的索引+1}
    
      g.FillEllipse(pb, 0, 0, 166, 88); {需要和定义的渐变效果的大小一样}
      //g.FillPath(pb,path); {直接画路径效果也一样}
    
      path.Free;
      pb.Free;
      g.Free;
    end;
    
    //可以通过点数组的指针创建路径画刷 var g : TGPGraphics; pts: array[0..2] of TGPPoint; pb: TGPPathGradientBrush; begin g := TGPGraphics.Create(Canvas.Handle); pts[0] := MakePoint(100, 0); pts[1] := MakePoint(200, 200); pts[2] := MakePoint(0, 200); pb:= TGPPathGradientBrush.Create(PGPPoint(@pts), 3); g.FillRectangle(pb, 0, 0, 200, 200); {没有指定中心颜色和周边颜色, 将分别默认黑色和白色} pb.Free; g.Free; end;
    //设置路径画刷的中心点 var g: TGPGraphics; path: TGPGraphicsPath; pb: TGPPathGradientBrush; num: Integer; const colors : array[0..0] of TGPColor = (aclAqua); begin g := TGPGraphics.Create(Canvas.Handle); path:= TGPGraphicsPath.Create; path.AddEllipse(0, 0, 140, 70); pb:= TGPPathGradientBrush.Create(path); pb.SetCenterPoint(MakePoint(120, 40)); {设置中心点} pb.SetCenterColor(MakeColor(255, 0, 0, 255)); num := 1; pb.SetSurroundColors(@colors, num); g.FillEllipse(pb, 0, 0, 140, 70); path.Free; pb.Free; g.Free; end;
    //使用灰度校正 var g: TGPGraphics; path: TGPGraphicsPath; pb: TGPPathGradientBrush; num: Integer; const colors: array[0..0] of TGPColor = (aclAqua); begin g := TGPGraphics.Create(Canvas.Handle); path := TGPGraphicsPath.Create; path.AddEllipse(0,0,166,88); pb := TGPPathGradientBrush.Create(path); pb.SetGammaCorrection(True); {使用灰度校正} num := 1; pb.SetSurroundColors(@colors, num); g.FillEllipse(pb, 0, 0, 166, 88); path.Free; pb.Free; g.Free; end;
    //多种颜色及位置 var g : TGPGraphics; pts: array[0..2] of TGPPoint; pb: TGPPathGradientBrush; const colors: array[0..2] of TGPColor = (aclGreen, aclAqua, aclBlue); pos: array[0..2] of Single = (0.0, 0.25, 1.0); {颜色位置需要 >0、<1, 是百分百} begin g := TGPGraphics.Create(Canvas.Handle); pts[0] := MakePoint(100, 0); pts[1] := MakePoint(200, 200); pts[2] := MakePoint(0, 200); pb:= TGPPathGradientBrush.Create(PGPPoint(@pts), 3); {根据点数组指针建立路径画刷} pb.SetInterpolationColors(@colors, @pos, 3); {设置颜色位置} g.FillRectangle(pb, 0, 0, 200, 200); pb.Free; g.Free; end;
    //设置多种周边颜色 var g: TGPGraphics; path: TGPGraphicsPath; pb: TGPPathGradientBrush; colors: array[0..9] of TGPColor; num: Integer; const pts : array[0..9] of TGPPoint = ((x:75 ; y:0 ), (x:100; y:50 ), (x:150; y:50 ), (x:112; y:75 ), (x:150; y:150), (x:75 ; y:100), (x:0 ; y:150), (x:37 ; y:75 ), (x:0 ; y:50 ), (x:50 ; y:50 )); begin g := TGPGraphics.Create(Canvas.Handle); path:= TGPGraphicsPath.Create; path.AddLines(PGPPoint(@pts), 10); pb:= TGPPathGradientBrush.Create(path); pb.SetCenterColor(MakeColor(255, 255, 0, 0)); colors[0] := MakeColor(255, 0, 0, 0); colors[1] := MakeColor(255, 0, 255, 0); colors[2] := MakeColor(255, 0, 0, 255); colors[3] := MakeColor(255, 255, 255, 255); colors[4] := MakeColor(255, 0, 0, 0); colors[5] := MakeColor(255, 0, 255, 0); colors[6] := MakeColor(255, 0, 0, 255); colors[7] := MakeColor(255, 255, 255, 255); colors[8] := MakeColor(255, 0, 0, 0); colors[9] := MakeColor(255, 0, 255, 0); num := 10; pb.SetSurroundColors(@colors, num); {设置多种周边颜色} g.FillPath(pb, path); pb.SetGammaCorrection(True); {使用灰度校正} g.TranslateTransform(200.0, 0.0); g.FillPath(pb, path); path.Free; pb.Free; g.Free; end;
    //描绘在不同的区域 var g : TGPGraphics; pb: TGPPathGradientBrush; p: TGPPen; colors: array[0..4] of TGPColor; num: Integer; const pts: array[0..4] of TGPPointF = ((x: 0.0 ; y: 0.0), (x: 160.0; y: 0.0), (x: 160.0; y: 200.0), (x: 80.0 ; y: 150.0), (x: 0.0 ; y: 200.0)); begin g := TGPGraphics.Create(Canvas.Handle); pb:= TGPPathGradientBrush.Create(PGPPointF(@pts), 5); colors[0] := MakeColor(255, 255, 0, 0); colors[1] := MakeColor(255, 0, 255, 0); colors[2] := MakeColor(255, 0, 255, 0); colors[3] := MakeColor(255, 0, 0, 255); colors[4] := MakeColor(255, 255, 0, 0); num := 5; pb.SetSurroundColors(@colors, num); pb.SetCenterColor(MakeColor(255, 255, 255, 255)); g.FillRectangle(pb, MakeRect(0, 0, 180, 220)); p := TGPPen.Create(aclBlack); g.DrawRectangle(p, MakeRect(0, 0, 180, 220)); p.Free; pb.Free; g.Free; end;
  • 相关阅读:
    我的Java学习路线图
    请求重定向和请求转发的区别
    PHP代码审计学习-php安全基础
    无密码正向直连内网linux目标机复现
    Windows API 学习
    Http请求走私
    免杀手法-tcp套字节传递shellcode学习
    自启动模块构造-计划任务
    自启动模块构造-快速启动目录
    进程注入免杀学习
  • 原文地址:https://www.cnblogs.com/del/p/1017210.html
Copyright © 2011-2022 走看看