{"id":151,"date":"2007-05-12T16:15:52","date_gmt":"2007-05-12T14:15:52","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/bitmaps-rotate-bitmap-any-angle-slow\/"},"modified":"2007-05-12T16:15:54","modified_gmt":"2007-05-12T14:15:54","slug":"bitmaps-rotate-bitmap-any-angle-slow","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/bitmaps-rotate-bitmap-any-angle-slow\/","title":{"rendered":"Bitmaps: Rotate Bitmap any angle (slow)"},"content":{"rendered":"<p>\/\/ Make sure to add Math to your uses clause.<\/p>\n<p>[code lang=&#8221;delphi&#8221;]procedure TForm1.bmp_rotate(src,dst:tbitmap;angle:extended);<br \/>\nvar<br \/>\n  c1x,c1y,c2x,c2y:integer;<br \/>\n  p1x,p1y,p2x,p2y:integer;<br \/>\n  radius,n:integer;<br \/>\n  alpha:extended;<br \/>\n  c0,c1,c2,c3:tcolor;<br \/>\nbegin<br \/>\n   \/\/calculate the angle to pi-format<br \/>\n  angle := (angle \/ 180) * pi;<\/p>\n<p>   \/\/ calculate the central points<br \/>\n  c1x := src.width div 2;<br \/>\n  c1y := src.height div 2;<br \/>\n  c2x := dst.width div 2;<br \/>\n  c2y := dst.height div 2;<\/p>\n<p>   \/\/ number of steps<br \/>\n  if c2x < c2y then\n    n := c2y \n  else \n    n := c2x;\n  dec (n,1);\n\n   \/\/ starting rotation\n  for p2x := 0 to n do begin\n    for p2y := 0 to n do begin\n      if p2x = 0 then\n        alpha:= pi\/2 \n      else\n        alpha := arctan2(p2y,p2x);\n      radius := round(sqrt((p2x*p2x)+(p2y*p2y)));\n      p1x := round(radius * cos(angle+alpha));\n      p1y := round(radius * sin(angle+alpha));\n             \n      c0 := src.canvas.pixels[c1x+p1x,c1y+p1y];\n      c1 := src.canvas.pixels[c1x-p1x,c1y-p1y];\n      c2 := src.canvas.pixels[c1x+p1y,c1y-p1x];\n      c3 := src.canvas.pixels[c1x-p1y,c1y+p1x];\n\n      dst.canvas.pixels[c2x+p2x,c2y+p2y]:=c0;\n      dst.canvas.pixels[c2x-p2x,c2y-p2y]:=c1;\n      dst.canvas.pixels[c2x+p2y,c2y-p2x]:=c2;\n      dst.canvas.pixels[c2x-p2y,c2y+p2x]:=c3;\n    end;\n    application.processmessages\n  end;\nend;\n\n\/\/ Here is how to call it\nprocedure TForm1.bmpRotateClick(Sender: TObject);\n Var\n  RAngle : Extended;\nbegin\n RAngle := StrToFloat(Edit1.Text);\nbmp_rotate(Image1.Picture.Bitmap,Image2.Picture.Bitmap, RAngle);\nend;\n[\/code]\n\n[tags]Delphi, Graphic[\/tags]\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ Make sure to add Math to your uses clause. [code lang=&#8221;delphi&#8221;]procedure TForm1.bmp_rotate(src,dst:tbitmap;angle:extended); var c1x,c1y,c2x,c2y:integer; p1x,p1y,p2x,p2y:integer; radius,n:integer; alpha:extended; c0,c1,c2,c3:tcolor; begin \/\/calculate the angle&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-2r","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/151"}],"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=151"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}