
TDIB.Rotate(Source: TDIB; CenterX, CenterY: Integer; Angle: Single) 以指定中心點旋轉來源圖像 Angle 度。範例以圖像中心為旋轉心,逆時針旋轉 45 度。同樣採用雙緩衝來源 DIB。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DIB, StdCtrls;
type
TForm1 = class(TForm)
DXPaintBox1: TDXPaintBox;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
Dib: TDIB;
procedure TForm1.FormCreate(Sender: TObject);
begin
Dib := TDIB.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Dib.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
const
ImgPath = 'C:\Temp\DX.jpg';
begin
Dib.LoadFromFile(ImgPath);
DXPaintBox1.DIB.Assign(Dib);
DXPaintBox1.Width := Dib.Width;
DXPaintBox1.Height := Dib.Height;
DXPaintBox1.Repaint;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
DXPaintBox1.DIB.Rotate(Dib, Dib.Width div 2, Dib.Height div 2, 45);
DXPaintBox1.DIB.Assign(Dib);
DXPaintBox1.Repaint;
end;
end.
object Form1: TForm1
ClientHeight = 142; ClientWidth = 226
OnCreate = FormCreate; OnDestroy = FormDestroy
object DXPaintBox1: TDXPaintBox
Left = 8; Top = 8; Width = 81; Height = 73
end
object Button1: TButton
Left = 143; Top = 78; Width = 75; Height = 25; Caption = 'Load'
end
object Button2: TButton
Left = 143; Top = 109; Width = 75; Height = 25; Caption = 'Rotate 45'
end
end