再学GDI+[54]: 路径

本例效果图:

代码文件:unit Unit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, ComCtrls, StdCtrls, ExtCtrls;
type
 TForm1 = class(TForm)
  Panel1: TPanel;
  Button1: TButton;
  TrackBar1: TTrackBar;
  TrackBar2: TTrackBar;
  TrackBar3: TTrackBar;
  TrackBar4: TTrackBar;
  TrackBar5: TTrackBar;
  TrackBar6: TTrackBar;
  PaintBox1: TPaintBox;
  procedure FormCreate(Sender: TObject);
  procedure TrackBar1Change(Sender: TObject);
  procedure TrackBar2Change(Sender: TObject);
  procedure TrackBar3Change(Sender: TObject);
  procedure TrackBar4Change(Sender: TObject);
  procedure TrackBar5Change(Sender: TObject);
  procedure TrackBar6Change(Sender: TObject);
  procedure PaintBox1Paint(Sender: TObject);
 end;
var
 Form1: TForm1;
implementation
{$R *.dfm}
uses GDIPOBJ, GDIPAPI;
procedure TForm1.FormCreate(Sender: TObject);
const
 n = 40;
begin
 TrackBar1.Min := -n;
 TrackBar1.Max := n;
 TrackBar2.Min := -n;
 TrackBar2.Max := n;
 TrackBar3.Min := -n;
 TrackBar3.Max := n;
 TrackBar4.Min := -n;
 TrackBar4.Max := n;
 TrackBar5.Min := -n;
 TrackBar5.Max := n;
 TrackBar6.Min := -n;
 TrackBar6.Max := n;
 TrackBar1.Position := 10;
 TrackBar2.Position := 0;
 TrackBar3.Position := 0;
 TrackBar4.Position := 10;
 TrackBar5.Position := 0;
 TrackBar6.Position := 0;
 Button1.OnClick := FormCreate;
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
var
 g: TGPGraphics;
 p: TGPPen;
 b: TGPBrush;
 path: TGPGraphicsPath;
 matrix: TGPMatrix;
 fontFamily: TGPFontFamily;
 StringFormat: TGPStringFormat;
 rect: TGPRect;
begin
 rect := MakeRect(20, 20, 180, 120);
 g := TGPGraphics.Create(PaintBox1.Canvas.Handle);
 p := TGPPen.Create(aclYellowGreen, 1);
 b := TGPHatchBrush.Create(HatchStyleSmallGrid, aclSilver, aclYellowGreen);
 fontFamily := TGPFontFamily.Create('Arial Black');
 StringFormat := TGPStringFormat.Create;
 StringFormat.SetAlignment(StringAlignmentCenter);
 StringFormat.SetLineAlignment(StringAlignmentCenter);
 path := TGPGraphicsPath.Create;
 path.AddRectangle(rect);
 path.AddEllipse(rect);
 path.AddString('ABC', -1, fontFamily, FontStyleRegular, 60, rect, StringFormat);
 matrix := TGPMatrix.Create;
 matrix.SetElements(TrackBar1.Position / 10,
           TrackBar2.Position / 10,
           TrackBar3.Position / 10,
           TrackBar4.Position / 10,
           TrackBar5.Position * 10,
           TrackBar6.Position * 10);
 path.Transform(matrix);
 g.FillPath(b, path);
 g.DrawPath(p, path);
 path.Free;
 StringFormat.Free;
 fontFamily.Free;
 b.Free;
 p.Free;
 g.Free;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
 PaintBox1.Repaint;
end;
procedure TForm1.TrackBar2Change(Sender: TObject);
begin
 PaintBox1.Repaint;
end;
procedure TForm1.TrackBar3Change(Sender: TObject);
begin
 PaintBox1.Repaint;
end;
procedure TForm1.TrackBar4Change(Sender: TObject);
begin
 PaintBox1.Repaint;
end;
procedure TForm1.TrackBar5Change(Sender: TObject);
begin
 PaintBox1.Repaint;
end;
procedure TForm1.TrackBar6Change(Sender: TObject);
begin
 PaintBox1.Repaint;
end;
end.

时间: 2024-10-30 16:43:32

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

再学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+[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+[56]: 路径

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

再学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