Delphi GDI + Learning Records (11): Path Gradient Brush

Source: Internet
Author: User

Path Gradient Paint Brush

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;

You can create a path through the pointer of an array of points brush

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.