程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 再學GDI+[29]: TGPPen - 自定義復合畫筆 - SetCompoundArray

再學GDI+[29]: TGPPen - 自定義復合畫筆 - SetCompoundArray

編輯:Delphi

本例效果圖:

代碼文件:unit Unit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls, ExtCtrls;
type
 TForm1 = class(TForm)
  LabeledEdit1: TLabeledEdit;
  RadioGroup1: TRadioGroup;
  procedure FormCreate(Sender: TObject);
  procedure FormPaint(Sender: TObject);
  procedure RadioGroup1Click(Sender: TObject);
  procedure LabeledEdit1Change(Sender: TObject);
 end;
var
 Form1: TForm1;
implementation
{$R *.dfm}
uses GDIPOBJ, GDIPAPI;
var
 arr1: array[0..5] of Single; {用於均分線復合畫筆; 數組大小沒有限制, 可用動態數 組}
 arr2: array[0..3] of Single; {用於粗細線復合畫筆; 數組大小沒有限制, 可用動態數 組}
procedure TForm1.FormCreate(Sender: TObject);
begin
 {均分線復合畫筆; 6 個元素決定 3 條子線; 數組元素為百分比, 應在 0-1 之間}
 arr1[0] := 0.00; {第一線起點}
 arr1[1] := 0.10; {第一線終點}
 arr1[2] := 0.45; {第二線起點}
 arr1[3] := 0.55; {第二線終點}
 arr1[4] := 0.90; {第三線起點}
 arr1[5] := 1.00; {第三線終點}
 {粗細線復合畫筆; 4 個元素決定 2 條子線; }
 arr2[0] := 0.00; {第一線起點}
 arr2[1] := 0.50; {第一線終點}
 arr2[2] := 0.90; {第二線起點}
 arr2[3] := 1.00; {第二線終點}
 LabeledEdit1.EditLabel.Caption := '筆寬';
 LabeledEdit1.Text := '10';
 RadioGroup1.Caption := '線型';
 RadioGroup1.Items.CommaText := '單實線,均分線,粗細線';
 RadioGroup1.ItemIndex := 0;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
 g: TGPGraphics;
 p: TGPPen;
 r: TRect;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 g.Clear($FFFFFFFF);
 p := TGPPen.Create(aclCoral);
 p.SetWidth(StrToFloatDef(LabeledEdit1.Text, 10));
 case RadioGroup1.ItemIndex of
  1: p.SetCompoundArray(@arr1, Length(arr1));
  2: p.SetCompoundArray(@arr2, Length(arr2));
 end;
 g.DrawLine(p, 0, 0, ClientWidth, ClientHeight);
 r := ClientRect;
 g.DrawEllipse(p, MakeRect(r));
 InflateRect(r, -ClientWidth p 4, -ClientHeight p 4);
 g.DrawLine(p, 0, 0, ClientWidth, ClientHeight);
 g.DrawRectangle(p, MakeRect(r));
 p.Free;
 g.Free;
end;
procedure TForm1.LabeledEdit1Change(Sender: TObject);
begin
 Repaint;
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
 Repaint;
end;
end.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved