• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Delphi的绘图功能[7]-PolyBezier、PolyBezierTo

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{PolyBezier 至少需要四个点做参数; 不改变画笔的当前位置}
procedure TForm1.Button1Click(Sender: TObject);
var
  pts: array[0..3] of TPoint;
begin
  Canvas.Pen.Width := 2;
  Canvas.Pen.Color := clRed;

  pts[0].X := 10; pts[0].Y := 10;  {起点}
  pts[1].X := 60; pts[1].Y := 10;  {控制点1}
  pts[2].X := 10; pts[2].Y := 100; {控制点2}
  pts[3].X := 60; pts[3].Y := 100; {终点}

  Canvas.PolyBezier(pts);

  Canvas.Pen.Width := 1;
  Canvas.Pen.Color := clWhite;
  Canvas.LineTo(ClientWidth, ClientHeight);
end;

{PolyBezierTo 最少只需要需要三个点, 它把当前位置当作第一点; 会改变画笔的当前位置}
procedure TForm1.Button2Click(Sender: TObject);
var
  pts: array[1..3] of TPoint; {从 1 开始的, 就 3 个元素}
begin
  Canvas.Pen.Width := 2;
  Canvas.Pen.Color := clRed;

  Canvas.MoveTo(10 + 82, 10);           {起点}

  //pts[0].X := 10; pts[0].Y := 10;
  pts[1].X := 60 + 82; pts[1].Y := 10;  {控制点1}
  pts[2].X := 10 + 82; pts[2].Y := 100; {控制点2}
  pts[3].X := 60 + 82; pts[3].Y := 100; {终点}

  Canvas.PolyBezierTo(pts);

  Canvas.Pen.Width := 1;
  Canvas.Pen.Color := clBlue;
  Canvas.LineTo(ClientWidth, ClientHeight);
end;

end.

//效果图:

//绘制多条贝塞尔线时, 每条线的终点也是下条线的起点.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{PolyBezier 绘制多条线时, 需要 3*x + 1 个点}
procedure TForm1.Button1Click(Sender: TObject);
var
  pts: array[0..6] of TPoint;
begin
  Canvas.Pen.Width := 2;
  Canvas.Pen.Color := clRed;

  pts[0].X := 10; pts[0].Y := 10;
  pts[1].X := 60; pts[1].Y := 10;
  pts[2].X := 10; pts[2].Y := 100;
  pts[3].X := 40; pts[3].Y := 100;
  pts[4].X := 100; pts[4].Y := 10;
  pts[5].X := 55; pts[5].Y := 99;
  pts[6].X := 70; pts[6].Y := 10;

  Canvas.PolyBezier(pts);
end;

{PolyBezierTo 绘制多条线时, 需要 3*x 个点}
procedure TForm1.Button2Click(Sender: TObject);
var
  pts: array[1..6] of TPoint;
begin
  Canvas.Pen.Width := 2;
  Canvas.Pen.Color := clRed;

  Canvas.MoveTo(10 + 82, 10);

  //pts[0].X := 10; pts[0].Y := 10;
  pts[1].X := 60 + 82; pts[1].Y := 10;
  pts[2].X := 10 + 82; pts[2].Y := 100;
  pts[3].X := 40 + 82; pts[3].Y := 100;
  pts[4].X := 100 + 82; pts[4].Y := 10;
  pts[5].X := 55 + 82; pts[5].Y := 99;
  pts[6].X := 70 + 82; pts[6].Y := 10;

  Canvas.PolyBezierTo(pts);
end;

end.

//效果图:


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
基于 Matlab 的 Alamouti 空时码及 MRC 接收分集仿真对比发布时间:2022-07-18
下一篇:
Matlab绘制直方图发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap