{"id":150,"date":"2007-05-12T16:15:07","date_gmt":"2007-05-12T14:15:07","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/bitmaps-rotate-bitmap-any-angle-2\/"},"modified":"2007-05-12T16:15:09","modified_gmt":"2007-05-12T14:15:09","slug":"bitmaps-rotate-bitmap-any-angle-2","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/bitmaps-rotate-bitmap-any-angle-2\/","title":{"rendered":"Bitmaps: Rotate Bitmap any angle 2"},"content":{"rendered":"<p>Diese Routine dreht eine Bitmap um jeden beliebigen Grad.<br \/>\nDabei wird die Zielbitmap in der Gr\u00f6\u00dfe so angepasst, da\u00df immer das gesamte Bitmap zu sehen ist (es wird NICHT an den R\u00e4ndern beschnitten!)<\/p>\n<p>Ben\u00f6tigt:<br \/>\nImage1 : Source-Bitmap<br \/>\nImage2 : Ziel-Bitmap (gr\u00f6\u00dfe wird angepasst)<br \/>\nUpDown1 : zum einstellen des Winkels<br \/>\n<!--more--><br \/>\n&#8212;&#8212;-8<---------snip-------------8<-------------snap-----------------\n\n[code lang=\"delphi\"]procedure TForm1.Button1Click(Sender: TObject);\nVar\n  Angle: Integer;\n  SAngle, CAngle: Extended;\n\n  PX1, PY1, PX2, PY2: Integer;\n  Cx1, Cy1, Cx2, Cy2: Integer;\n\n  SrcW, SrcH, DesW, DesH: Integer;\n  TmpAngle: Integer;\n  TmpHSIN, TmpWSIN: Extended;\n  dPP, dPPAngle : Extended;\n\n  X, Y: Integer;\nbegin\n  Angle:=abs(UpDown1.Position mod 360);\n  SAngle:= Sin(Angle*(PI\/180));\n  CAngle:= Cos(Angle*(PI\/180));\n\n  SrcW:= Image1.Width;\n  SrcH:= Image1.Height;\n\n  If ((Angle>=0) and (Angle<=90)) or\n     ((Angle>180) and (Angle<=270)) then\n  Begin \/\/ I, III of cood\n    If Angle>180 then<br \/>\n      TmpAngle:= Angle-180 \/\/ Min=1; Max=90<br \/>\n    Else<br \/>\n      TmpAngle:= Angle;<\/p>\n<p>    dPP := Sqrt(Sqr(SrcW) + Sqr(SrcH));<br \/>\n    dPPAngle:= ArcTan(SrcH\/SrcW)\/(PI\/180);<br \/>\n    TmpHSIN:= Sin(((90-TmpAngle)+dPPAngle)*(PI\/180));<br \/>\n    TmpWSIN:= Sin((TmpAngle+dPPAngle)*(PI\/180));<\/p>\n<p>    DesW:= Round(TmpHSIN*dPP);<br \/>\n    DesH:= Round(TmpWSIN*dPP);<br \/>\n  End Else<br \/>\n  Begin \/\/ II, IV of cood<br \/>\n    If Angle>270 then<br \/>\n      TmpAngle:= Angle-180 \/\/ Min=91; Max=180<br \/>\n    Else<br \/>\n      TmpAngle:= Angle;<\/p>\n<p>    dPP := Sqrt(Sqr(SrcW) + Sqr(SrcH));<br \/>\n    dPPAngle:= ArcTan(SrcH\/SrcW)\/(PI\/180);<br \/>\n    TmpHSIN:= Sin(((TmpAngle-90)+dPPAngle)*(PI\/180));<br \/>\n    TmpWSIN:= Sin(((180-TmpAngle)+dPPAngle)*(PI\/180));<\/p>\n<p>    DesW:= Round(TmpHSIN*dPP);<br \/>\n    DesH:= Round(TmpWSIN*dPP);<br \/>\n  End;<br \/>\n{  ShowMessage(&#8216;W:&#8217;+IntToStr(SrcW)+#9&#8217;H: &#8216;+IntToStr(SrcH)+#9&#8217;D:<br \/>\n&#8216;+FloatToStr(dPP)+#13+<br \/>\n              &#8216;SA:&#8217;+FloatToStr(dPPAngle)+#9&#8217;TA:&#8217;+FloatToStr(TmpAngle));{}<\/p>\n<p>  Cx1:= SrcW div 2;<br \/>\n  Cy1:= SrcH div 2;<br \/>\n  Cx2:= DesW div 2;<br \/>\n  Cy2:= DesH div 2;<\/p>\n<p>  Image2.Width:= DesW;<br \/>\n  Image2.Height:= DesH;<br \/>\n  Image2.Picture.Assign(nil);<br \/>\n  For Y:=0 to DesH-1 do<br \/>\n  Begin<br \/>\n    For X:=0 to DesW-1 do<br \/>\n    Begin<br \/>\n      PX2:= X- Cx2;<br \/>\n      PY2:= Y- Cy2;<br \/>\n      PX1:= Round((CAngle*Px2)+(SAngle*Py2)+Cx1);<br \/>\n      PY1:= Round(-(SAngle*Px2)+(CAngle*Py2)+Cy1);<\/p>\n<p>      If (PX1>=0) and (PX1=0) and (PY1[\/code]<br \/>\n<---------snip-------------8<-------------snap-----------------\n\n[tags]Delphi, Graphic[\/tags]\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Diese Routine dreht eine Bitmap um jeden beliebigen Grad. Dabei wird die Zielbitmap in der Gr\u00f6\u00dfe so angepasst, da\u00df immer das gesamte Bitmap&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[75,101],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-2q","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/150"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=150"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/150\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}