再学GDI+[48]: 路径

本例效果图:

代码文件:unit Unit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;
type
 TForm1 = class(TForm)
  CheckBox1: TCheckBox;
  CheckBox2: TCheckBox;
  procedure FormCreate(Sender: TObject);
  procedure FormPaint(Sender: TObject);
  procedure CheckBox1Click(Sender: TObject);
  procedure CheckBox2Click(Sender: TObject);
 end;
var
 Form1: TForm1;
implementation
{$R *.dfm}
uses GDIPOBJ, GDIPAPI;
procedure TForm1.FormCreate(Sender: TObject);
begin
 CheckBox1.Caption := 'CloseFigure';
 CheckBox2.Caption := 'CloseAllFigures';
end;
procedure TForm1.FormPaint(Sender: TObject);
var
 g: TGPGraphics;
 path: TGPGraphicsPath;
 p: TGPPen;
 b: TGPBrush;
 pts1,pts2,pts3: array[0..2] of TGPPoint;
 i: Integer;
begin
 pts1[0] := MakePoint(0, 30);
 pts1[1] := MakePoint(30, 0);
 pts1[2] := MakePoint(60, 30);
 for i := 0 to Length(pts1) do
 begin
  pts2[i].X := pts1[i].X + 80;
  pts2[i].Y := pts1[i].Y + 20;
  pts3[i].X := pts2[i].X + 80;
  pts3[i].Y := pts2[i].Y + 20;
 end;
 g := TGPGraphics.Create(Canvas.Handle);
 path := TGPGraphicsPath.Create;
 path.StartFigure;
 path.AddLines(PGPPoint(@pts1), Length(pts1));
 path.StartFigure;
 path.AddLines(PGPPoint(@pts2), Length(pts2));
 path.StartFigure;
 path.AddLines(PGPPoint(@pts3), Length(pts3));
 if CheckBox1.Checked then path.CloseFigure;
 if CheckBox2.Checked then path.CloseAllFigures;
 p := TGPPen.Create(aclRed, 2);
 b := TGPSolidBrush.Create(aclYellow);
 g.DrawPath(p, path);
 b.Free;
 p.Free;
 path.Free;
 g.Free;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
 Repaint;
end;
procedure TForm1.CheckBox2Click(Sender: TObject);
begin
 Repaint;
end;
end.

时间: 2024-08-21 06:08:45

再学GDI+[48]: 路径的相关文章

再学GDI+[69]: 路径画刷(9)

SetInterpolationColors 与 SetSurroundColors 的区别 本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, StdCtrls, ExtCtrls; type TForm1 = class(TForm) procedure FormPaint(Sen

再学GDI+[58]: 路径

本例演示了把路径中的数据保存到一个文本文件, 然后再读出的过程. 本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; procedure FormCreate(

再学GDI+[57]: 路径

路径的 Widen 方法可以把路径中的线, 根据指定画笔的宽度与样式, 转换为一个范围(有点 类似区域); 但转换后再描绘路径就只能使用 FillPath 而不是 DrawPath 了. 本例没有测试它 的两个默认参数, 因为前面已多次提到了. 本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdC

再学GDI+[56]: 路径

通过路径的 Warp 方法可以让路径在一个范围内(四个点决定的范围)变换; 第一个参数可以是 3 个点或 4 个点的数组, 如果是 3 个的数组, 那么第 4 个点将自动跟 随一个平行四边形; 第二个参数用来指定点数组的个数, 本例就是通过这个参数控制了点的个数; 第三个参数是一个矩形, 这个矩形应该是路径的外接矩形, 之后的参数都是可选的; 第四个参数也是一个矩阵变换, 因由专门的 例子 , 这里没有尝试; 第五个参数是 TWarpMode(WarpModePerspective, WarpM

再学GDI+[65]: 路径画刷(5)

本例效果图: 代码文件: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

再学GDI+[64]: 路径画刷(4)

在本例中没有指定 CenterColor, 将默认白色; SurroundColors 原来是对应路径中的点(但按下面的做法在椭圆里不灵). 本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) procedure FormPaint(Sender: T

再学GDI+[59]: 路径

通过路径的辅助类 TGPGraphicsPathIterator , 可以获得更多路径数据和控制能力. 本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; pr

再学GDI+[55]: 路径

通过路径的 Flatten 方法可以把路径中的曲线拉直, 拉直到什么程度是由它的第二个参数( 默认0.25)决定的; 它的第一个参数又是一个矩阵变换, 也就是说 Flatten 可以同时进行矩阵 变换, 本例没有测试它, 其详情参见: http://www.cnblogs.com/del/archive/2008/06/20/1226293.html 本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Varia

再学GDI+[53]: 路径

本例效果图: 代码文件:unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) RadioGroup1: TRadioGroup; procedure FormCreate(Sender: TObject); procedure FormP