GdiPlus[47]: IGPMatrix 矩阵(二)
生活随笔
收集整理的這篇文章主要介紹了
GdiPlus[47]: IGPMatrix 矩阵(二)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
IGPMatrix 的屬性與方法:
//方法 IGPMatrix.Reset; { 重置 Matrix 得到單位矩陣(斜對角線是1其他是0) } IGPMatrix.Translate(); { 平移 } IGPMatrix.Scale(); { 放縮 } IGPMatrix.Rotate(); { 旋轉(沿(0,0)點, 順時針) } IGPMatrix.RotateAt(); { 沿指定點, 順時針旋轉 } IGPMatrix.Shear(); { 剪切(或叫錯切、斜切) } IGPMatrix.Invert; { 反轉 } IGPMatrix.Multiply(); { 與指定的 Matrix 相乘 } IGPMatrix.TransformPoint(); { 對指定點應用此 Matrix 變換 } IGPMatrix.TransformPoints(); { 對點數組應用此 Matrix 變換 } IGPMatrix.TransformVector(); { 對指定點應用此 Matrix 變換中的縮放和旋轉變換 } IGPMatrix.TransformVectors(); { 對點數組應用此 Matrix 變換中的縮放和旋轉變換 } IGPMatrix.SetElements(); { 設置 Matrix 各元素 } IGPMatrix.Clone; { 克隆副本 } IGPMatrix.Equals(); { 判斷是否相等 }//屬性 IGPMatrix.Elements; { 獲取 Matrix 各元素構成的數組 } IGPMatrix.OffsetX; { 獲取 Matrix.Elements.DX } IGPMatrix.OffsetY; { 獲取 Matrix.Elements.DY } IGPMatrix.IsInvertible; { 判斷 Matrix 是否可逆轉 } IGPMatrix.IsIdentity; { 判斷 Matrix 是否是單位矩陣(斜對角線是1其他是0) }
下面的例子用到了其中的 Reset、Translate、Scale、Rotate、Shear、Invert 方法:
代碼:
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Button1: TButton;Button2: TButton;Button3: TButton;Button4: TButton;Button5: TButton;Button6: TButton;Memo1: TMemo;procedure FormCreate(Sender: TObject);procedure FormPaint(Sender: TObject);procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);procedure Button3Click(Sender: TObject);procedure Button4Click(Sender: TObject);procedure Button5Click(Sender: TObject);procedure Button6Click(Sender: TObject);end;varForm1: TForm1;implementation{$R *.dfm}usesGdiPlus;varMatrix: IGPMatrix;//用字符串的形式返回 Matrix 數據, 用于查看 function ViewMatrix(Matrix: IGPMatrix): string; constfmt = '%f'#9'%f'#9'0'#13#10#13#10'%f'#9'%f'#9'0'#13#10#13#10'%f'#9'%f'#9'1'; beginResult := Format(fmt, [Matrix.Elements.M11,Matrix.Elements.M12,Matrix.Elements.M21,Matrix.Elements.M22,Matrix.Elements.DX,Matrix.Elements.DY]); end;//初識化 procedure TForm1.FormCreate(Sender: TObject); beginButton1.Caption := '重置 (Reset)';Button2.Caption := '反轉 (Invert)';Button3.Caption := '平移 (Translate)';Button4.Caption := '比例 (Scale)';Button5.Caption := '旋轉 (Rotate)';Button6.Caption := '錯切 (Shear)';Matrix := TGPMatrix.Create; end;//繪圖 procedure TForm1.FormPaint(Sender: TObject); varImage: IGPImage;Graphics: IGPGraphics;Rect: TGPRect; beginImage := TGPImage.Create('C:\GdiPlusImg\Apple.gif');Rect.Initialize(20, 20, 80, 80);Graphics := TGPGraphics.Create(Handle);Graphics.MultiplyTransform(Matrix);Graphics.DrawImage(Image, Rect);Graphics.DrawRectangle(TGPPen.Create($FFFF0000, 2), Rect); end;//重置到單位矩陣 procedure TForm1.Button1Click(Sender: TObject); beginMatrix.Reset;Memo1.Text := ViewMatrix(Matrix);Repaint; end;//反轉變換 procedure TForm1.Button2Click(Sender: TObject); beginMatrix.Invert;Memo1.Text := ViewMatrix(Matrix);Repaint; end;//平移變換 procedure TForm1.Button3Click(Sender: TObject); beginMatrix.Translate(1.5, 3);Memo1.Text := ViewMatrix(Matrix);Repaint; end;//比例變換 procedure TForm1.Button4Click(Sender: TObject); beginMatrix.Scale(0.75, 1.5);Memo1.Text := ViewMatrix(Matrix);Repaint; end;//旋轉變換 procedure TForm1.Button5Click(Sender: TObject); beginMatrix.Rotate(15);Memo1.Text := ViewMatrix(Matrix);Repaint; end;//錯切變換 procedure TForm1.Button6Click(Sender: TObject); beginMatrix.Shear(0.2, 0.5);Memo1.Text := ViewMatrix(Matrix);Repaint; end;end.
窗體:
object Form1: TForm1Left = 0Top = 0Caption = 'Form1'ClientHeight = 200ClientWidth = 377Color = clBtnFaceFont.Charset = DEFAULT_CHARSETFont.Color = clWindowTextFont.Height = -11Font.Name = 'Tahoma'Font.Style = []OldCreateOrder = FalseOnCreate = FormCreateOnPaint = FormPaintPixelsPerInch = 96TextHeight = 13object Button1: TButtonLeft = 185Top = 8Width = 90Height = 25Caption = 'Button1'TabOrder = 0OnClick = Button1Clickendobject Button2: TButtonLeft = 281Top = 8Width = 90Height = 25Caption = 'Button2'TabOrder = 1OnClick = Button2Clickendobject Button3: TButtonLeft = 185Top = 39Width = 90Height = 25Caption = 'Button3'TabOrder = 2OnClick = Button3Clickendobject Button4: TButtonLeft = 281Top = 39Width = 90Height = 25Caption = 'Button4'TabOrder = 3OnClick = Button4Clickendobject Button5: TButtonLeft = 185Top = 70Width = 90Height = 25Caption = 'Button5'TabOrder = 4OnClick = Button5Clickendobject Memo1: TMemoLeft = 185Top = 111Width = 181Height = 81Lines.Strings = ('Memo1')TabOrder = 5endobject Button6: TButtonLeft = 281Top = 70Width = 90Height = 25Caption = 'Button6'TabOrder = 6OnClick = Button6Clickend end
轉載于:https://my.oschina.net/hermer/blog/319896
總結
以上是生活随笔為你收集整理的GdiPlus[47]: IGPMatrix 矩阵(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 硬链接 和软链接
- 下一篇: linux ubuntu系统安装及卸载o