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 FormPaint(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
cvs: TCanvas;
Rgn: HRGN;
procedure TForm1.FormCreate(Sender: TObject);
begin
cvs := TCanvas.Create;
cvs.Handle := GetDC(Handle);
RadioGroup1.Items.CommaText :=
'原始,橫向移動,縱向移動,橫向比例,縱向比例,放大,縮小,水平鏡像,垂直鏡像,橫向斜切,縱向斜切,旋轉';
RadioGroup1.ItemIndex := 0;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DeleteObject(Rgn);
cvs.Free;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
{繪制}
cvs.Brush.Color := clSilver;
cvs.Brush.Style := bsDiagCross;
FillRgn(cvs.Handle, Rgn, cvs.Brush.Handle);
cvs.Brush.Color := clRed;
cvs.Brush.Style := bsSolid;
FrameRgn(cvs.Handle, Rgn, cvs.Brush.Handle, 2, 2);
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
var
RgnDataSize: Integer; {區域數據緩沖區的大小}
RgnData: PRgnData; {區域數據指針}
TXF: TXForm; {坐標轉換的矩陣結構}
begin
cvs.Font.Size := 120;
cvs.Font.Style := [fsBold];
SetBkMode(cvs.Handle, TRANSPARENT);
{建立路徑}
BeginPath(cvs.Handle);
cvs.TextOut(100, 0, 'F');
EndPath(cvs.Handle);
{將路徑轉換為區域}
Rgn := PathToRegion(cvs.Handle);
{獲取區域數據}
RgnDataSize := GetRegionData(Rgn, 0, nil);
GetMem(RgnData, RgnDataSize);
GetRegionData(Rgn, RgnDataSize, RgnData);
case RadioGroup1.ItemIndex of
0: begin {原始效果, 無變換}
TXF.eM11 := 1;
TXF.eM12 := 0;
TXF.eM21 := 0;
TXF.eM22 := 1;
TXF.eDx := 0;
TXF.eDy := 0;
end;
1: begin {右移 100}
TXF.eM11 := 1;
TXF.eM12 := 0;
TXF.eM21 := 0;
TXF.eM22 := 1;
TXF.eDx := 100;
TXF.eDy := 0;
end;
2: begin {上移 40}
TXF.eM11 := 1;
TXF.eM12 := 0;
TXF.eM21 := 0;
TXF.eM22 := 1;
TXF.eDx := 0;
TXF.eDy := -40;
end;
3: begin {橫向放大 1.5}
TXF.eM11 := 1.5;
TXF.eM12 := 0;
TXF.eM21 := 0;
TXF.eM22 := 1;
TXF.eDx := 0;
TXF.eDy := 0;
end;
4: begin {縱向放大 1.5}
TXF.eM11 := 1;
TXF.eM12 := 0;
TXF.eM21 := 0;
TXF.eM22 := 1.5;
TXF.eDx := 0;
TXF.eDy := 0;
end;
5: begin {整體放大 1.5 倍}
TXF.eM11 := 1.5;
TXF.eM12 := 0;
TXF.eM21 := 0;
TXF.eM22 := 1.5;
TXF.eDx := 0;
TXF.eDy := 0;
end;
6: begin {整體縮小一半}
TXF.eM11 := 0.5;
TXF.eM12 := 0;
TXF.eM21 := 0;
TXF.eM22 := 0.5;
TXF.eDx := 0;
TXF.eDy := 0;
end;
7: begin {水平鏡像}
TXF.eM11 := -1;
TXF.eM12 := 0;
TXF.eM21 := 0;
TXF.eM22 := 1;
TXF.eDx := 200; {需要右移一些才能看到}
TXF.eDy := 0;
end;
8: begin {垂直鏡像}
TXF.eM11 := 1;
TXF.eM12 := 0;
TXF.eM21 := 0;
TXF.eM22 := -1;
TXF.eDx := 0;
TXF.eDy := 200; {需要下移一些才能看到}
end;
9: begin {橫向斜切}
TXF.eM11 := 1;
TXF.eM12 := 0.75;
TXF.eM21 := 0;
TXF.eM22 := 1;
TXF.eDx := 0;
TXF.eDy := 0;
end;
10: begin {縱向斜切}
TXF.eM11 := 1;
TXF.eM12 := 0;
TXF.eM21 := 0.75;
TXF.eM22 := 1;
TXF.eDx := 0;
TXF.eDy := 0;
end;
11: begin {旋轉 30 度}
TXF.eM11 := Cos(30*PI/180);
TXF.eM12 := Sin(30*PI/180);
TXF.eM21 := -Sin(30*PI/180);
TXF.eM22 := Cos(30*PI/180);
TXF.eDx := 0;
TXF.eDy := 0;
end;
end;
{執行變換並重繪}
Rgn := ExtCreateRegion(@TXF, RgnDataSize, RgnData^);
Repaint;
FreeMem(RgnData);
end;
end.
窗體文件:
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClIEntHeight = 259
ClIEntWidth = 433
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
OnCreate = FormCreate
OnDestroy = FormDestroy
OnPaint = FormPaint
PixelsPerInch = 96
TextHeight = 13
object RadioGroup1: TRadioGroup
Left = 320
Top = 8
Width = 103
Height = 243
Caption = 'RadioGroup1'
TabOrder = 0
OnClick = RadioGroup1Click
end
end