Diese Routine dreht eine Bitmap um jeden beliebigen Grad.
Dabei wird die Zielbitmap in der Größe so angepasst, daß immer das gesamte Bitmap zu sehen ist (es wird NICHT an den Rändern beschnitten!)
Benötigt:
Image1 : Source-Bitmap
Image2 : Ziel-Bitmap (größe wird angepasst)
UpDown1 : zum einstellen des Winkels
——-8<---------snip-------------8<-------------snap-----------------
[code lang="delphi"]procedure TForm1.Button1Click(Sender: TObject);
Var
Angle: Integer;
SAngle, CAngle: Extended;
PX1, PY1, PX2, PY2: Integer;
Cx1, Cy1, Cx2, Cy2: Integer;
SrcW, SrcH, DesW, DesH: Integer;
TmpAngle: Integer;
TmpHSIN, TmpWSIN: Extended;
dPP, dPPAngle : Extended;
X, Y: Integer;
begin
Angle:=abs(UpDown1.Position mod 360);
SAngle:= Sin(Angle*(PI/180));
CAngle:= Cos(Angle*(PI/180));
SrcW:= Image1.Width;
SrcH:= Image1.Height;
If ((Angle>=0) and (Angle<=90)) or
((Angle>180) and (Angle<=270)) then
Begin // I, III of cood
If Angle>180 then
TmpAngle:= Angle-180 // Min=1; Max=90
Else
TmpAngle:= Angle;
dPP := Sqrt(Sqr(SrcW) + Sqr(SrcH));
dPPAngle:= ArcTan(SrcH/SrcW)/(PI/180);
TmpHSIN:= Sin(((90-TmpAngle)+dPPAngle)*(PI/180));
TmpWSIN:= Sin((TmpAngle+dPPAngle)*(PI/180));
DesW:= Round(TmpHSIN*dPP);
DesH:= Round(TmpWSIN*dPP);
End Else
Begin // II, IV of cood
If Angle>270 then
TmpAngle:= Angle-180 // Min=91; Max=180
Else
TmpAngle:= Angle;
dPP := Sqrt(Sqr(SrcW) + Sqr(SrcH));
dPPAngle:= ArcTan(SrcH/SrcW)/(PI/180);
TmpHSIN:= Sin(((TmpAngle-90)+dPPAngle)*(PI/180));
TmpWSIN:= Sin(((180-TmpAngle)+dPPAngle)*(PI/180));
DesW:= Round(TmpHSIN*dPP);
DesH:= Round(TmpWSIN*dPP);
End;
{ ShowMessage(‘W:’+IntToStr(SrcW)+#9’H: ‘+IntToStr(SrcH)+#9’D:
‘+FloatToStr(dPP)+#13+
‘SA:’+FloatToStr(dPPAngle)+#9’TA:’+FloatToStr(TmpAngle));{}
Cx1:= SrcW div 2;
Cy1:= SrcH div 2;
Cx2:= DesW div 2;
Cy2:= DesH div 2;
Image2.Width:= DesW;
Image2.Height:= DesH;
Image2.Picture.Assign(nil);
For Y:=0 to DesH-1 do
Begin
For X:=0 to DesW-1 do
Begin
PX2:= X- Cx2;
PY2:= Y- Cy2;
PX1:= Round((CAngle*Px2)+(SAngle*Py2)+Cx1);
PY1:= Round(-(SAngle*Px2)+(CAngle*Py2)+Cy1);
If (PX1>=0) and (PX1=0) and (PY1[/code]
<---------snip-------------8<-------------snap-----------------
[tags]Delphi, Graphic[/tags]
0 Kommentare zu “Bitmaps: Rotate Bitmap any angle 2”