GdiPlus[9]: IGPTextureBrush 变换


TranslateTransform: 平移;
ScaleTransform: 放缩;
RotateTransform: 旋转;

通过 MultiplyTransform 方法和 Transform 属性, 能完成包括上述变换在内的更多变换.

ResetTransform 方法是重置变换.

这些方法和属性, 在 IGPGraphics 中都有, 在 IGPGraphics 中详细学习更合适些.

测试效果图:

GdiPlus[9]: IGPTextureBrush 变换

代码文件:


unit Unit1;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ExtCtrls, StdCtrls, ComCtrls;



type

  TForm1 = class(TForm)

    TrackBar1: TTrackBar;

    TrackBar2: TTrackBar;

    TrackBar3: TTrackBar;

    TrackBar4: TTrackBar;

    TrackBar5: TTrackBar;

    Label1: TLabel;

    Label2: TLabel;

    Label3: TLabel;

    PaintBox1: TPaintBox;

    procedure TrackBar1Change(Sender: TObject);

    procedure FormCreate(Sender: TObject);

    procedure PaintBox1Paint(Sender: TObject);

  end;



var

  Form1: TForm1;



implementation



{$R *.dfm}



uses GdiPlus, GdiPlusHelpers;



var

  Brush1: IGPTextureBrush;

  Image: IGPImage;

  Rect: TGPRect;

  RX: Single = 1.0;

  RY: Single = 1.0;



procedure TForm1.FormCreate(Sender: TObject);

begin

  TrackBar1.Min := -200;

  TrackBar1.Max := 200;



  TrackBar2.Min := -200;

  TrackBar2.Max := 200;



  TrackBar3.Min := -99;

  TrackBar3.Max := 99;



  TrackBar4.Min := -99;

  TrackBar4.Max := 99;



  TrackBar5.Min := -180;

  TrackBar5.Max := 180;



  TrackBar2.OnChange := TrackBar1.OnChange;

  TrackBar3.OnChange := TrackBar1.OnChange;

  TrackBar4.OnChange := TrackBar1.OnChange;

  TrackBar5.OnChange := TrackBar1.OnChange;



  Image := TGPImage.Create('C:\GdiPlusImg\HouseAndTree.gif');

  Brush1 := TGPTextureBrush.Create(Image);

  Rect.Initialize(0, 0, PaintBox1.Width, PaintBox1.Height);

end;



procedure TForm1.PaintBox1Paint(Sender: TObject);

begin

  Brush1.ResetTransform;

  Brush1.TranslateTransform(TrackBar1.Tag, TrackBar2.Tag);

  Brush1.ScaleTransform(RX + TrackBar3.Tag / 100, RY + TrackBar4.Tag / 100);

  Brush1.RotateTransform(TrackBar5.Tag);

  PaintBox1.ToGPGraphics.FillRectangle(Brush1, Rect);

end;



procedure TForm1.TrackBar1Change(Sender: TObject);

begin

  with TTrackBar(Sender) do Tag := Position;

  PaintBox1.Repaint;

end;



end.


 
   

窗体文件:


object Form1: TForm1

  Left = 0

  Top = 0

  Caption = 'Form1'

  ClientHeight = 234

  ClientWidth = 423

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'Tahoma'

  Font.Style = []

  OldCreateOrder = False

  OnCreate = FormCreate

  PixelsPerInch = 96

  TextHeight = 13

  object Label1: TLabel

    Left = 259

    Top = 13

    Width = 28

    Height = 13

    Caption = #24179#31227':'

  end

  object Label2: TLabel

    Left = 259

    Top = 90

    Width = 28

    Height = 13

    Caption = #25918#32553':'

  end

  object Label3: TLabel

    Left = 259

    Top = 169

    Width = 28

    Height = 13

    Caption = #26059#36716':'

  end

  object PaintBox1: TPaintBox

    Left = 8

    Top = 8

    Width = 225

    Height = 217

    OnPaint = PaintBox1Paint

  end

  object TrackBar1: TTrackBar

    Left = 251

    Top = 32

    Width = 169

    Height = 23

    ShowSelRange = False

    TabOrder = 0

    OnChange = TrackBar1Change

  end

  object TrackBar2: TTrackBar

    Left = 251

    Top = 56

    Width = 169

    Height = 23

    ShowSelRange = False

    TabOrder = 1

  end

  object TrackBar3: TTrackBar

    Left = 251

    Top = 109

    Width = 169

    Height = 23

    ShowSelRange = False

    TabOrder = 2

  end

  object TrackBar4: TTrackBar

    Left = 251

    Top = 133

    Width = 169

    Height = 23

    ShowSelRange = False

    TabOrder = 3

  end

  object TrackBar5: TTrackBar

    Left = 251

    Top = 188

    Width = 169

    Height = 23

    ShowSelRange = False

    TabOrder = 4

  end

end


 
   

你可能感兴趣的:(text)