unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, pngimage, ExtCtrls,Math, JvGradient, StdCtrls ;
type
TForm1 =
class(TForm)
TrackBar1: TTrackBar;
Image2: TImage;
lbl_position: TLabel;
Image1: TImage;
procedure TrackBar1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure DrawRotatedGraphic (aCanvas: TCanvas; aGraphic: TGraphic;
aAngle: Double; aOffsetX, aOffsetY: Integer);
var
svMode: Integer;
Mat, svMat: tagXFORM;
si, co: Extended;
begin
// aktuellen Zustand retten
svMode := SetGraphicsMode(aCanvas.Handle, GM_ADVANCED);
if (svMode = GM_ADVANCED)
then
GetWorldTransform(aCanvas.Handle, svMat);
// Verschiebung in den Usprung
FillChar (Mat, SizeOf(Mat), 0);
Mat.em11 := 1.0;
Mat.em22 := 1.0;
Mat.eDx := -(aOffsetX + aGraphic.Width / 2);
Mat.eDy := -(aOffsetY + aGraphic.Height / 2);
SetWorldTransform(aCanvas.Handle, Mat);
// Verdrehung
SinCos (aAngle * Pi / 180, si, co);
FillChar (Mat, SizeOf(Mat), 0);
Mat.em11 := co;
Mat.em12 := si;
Mat.em21 := -si;
Mat.em22 := co;
ModifyWorldTransform(aCanvas.Handle, Mat, MWT_RIGHTMULTIPLY);
// Zurückschieben
FillChar (Mat, SizeOf(Mat), 0);
Mat.em11 := 1.0;
Mat.em22 := 1.0;
Mat.eDx := (aOffsetX + aGraphic.Width / 2);
Mat.eDy := (aOffsetY + aGraphic.Height / 2);
ModifyWorldTransform(aCanvas.Handle, Mat, MWT_RIGHTMULTIPLY);
// Bitmap zeichnen
aCanvas.Draw(aOffsetX, aOffsetY, aGraphic);
// alten Zustand wiederherstellen
if (svMode = GM_ADVANCED)
then
SetWorldTransform(aCanvas.Handle, svMat)
else
SetGraphicsMode(aCanvas.Handle, svMode);
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
lbl_position.Caption:=inttostr(TrackBar1.Position);
DrawRotatedGraphic(Image2.Canvas,Image2.Picture.Graphic,TrackBar1.Position,0,0);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
lbl_position.Caption:=inttostr(TrackBar1.Position);
end;
end.