FlattenPath 和 WidenPath 都能够把路径中的 Bezier 线转换为近似的直线; 不同的是: 用 WidenPath 转换后貌似加宽了线, 其实它是转换成了一个包围路径的新路径(类似区域).
本例效果图:
代码文件:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) RadioGroup1: TRadioGroup; procedure FormPaint(Sender: TObject); procedure FormCreate(Sender: TObject); procedure RadioGroup1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin RadioGroup1.Items.CommaText := 'Path,FlattenPath,WidenPath'; RadioGroup1.ItemIndex := 0; end; procedure TForm1.FormPaint(Sender: TObject); type TPArr = array[0..0] of TPoint; TTArr = array[0..0] of Byte; var pts: ^TPArr; types: ^TTArr; count: Integer; i,x,y: Integer; begin Canvas.Font.Size := 150; Canvas.Font.Style := [fsBold]; SetBkMode(Canvas.Handle, TRANSPARENT); BeginPath(Canvas.Handle); Canvas.TextOut(50, 0, 'D'); Canvas.Arc(20, 20, 220, 220, 120, 120, 20, 120); EndPath(Canvas.Handle); Canvas.Pen.Width := 6; if RadioGroup1.ItemIndex = 1 then FlattenPath(Canvas.Handle); if RadioGroup1.ItemIndex = 2 then WidenPath(Canvas.Handle); Canvas.Pen.Color := clWhite; count := GetPath(Canvas.Handle, pts^, types^, 0); GetMem(pts, count*SizeOf(TPoint)); GetMem(types, count); count := GetPath(Canvas.Handle, pts^, types^, count); Text := '路径中点的总数是: ' + IntToStr(count); StrokePath(Canvas.Handle); Canvas.Brush.Color := clRed; for i := 0 to count - 1 do begin x := pts^[i].X; y := pts^[i].Y; Canvas.FillRect(Rect(x-1,y-1,x+1,y+1)); end; FreeMem(pts); FreeMem(types); end; procedure TForm1.RadioGroup1Click(Sender: TObject); begin Repaint; end; end.窗体文件:
object Form1: TForm1 Left = 352 Top = 227 Caption = 'Form1' ClientHeight = 215 ClientWidth = 339 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False Position = poDesigned OnCreate = FormCreate OnPaint = FormPaint PixelsPerInch = 96 TextHeight = 13 object RadioGroup1: TRadioGroup Left = 240 Top = 80 Width = 91 Height = 127 Caption = 'RadioGroup1' TabOrder = 0 OnClick = RadioGroup1Click end end关于描绘路径中的点, 参见: http://www.cnblogs.com/del/archive/2008/05/26/1207423.html