{"id":149,"date":"2007-05-12T16:13:46","date_gmt":"2007-05-12T14:13:46","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/bitmaps-rotate-image-90%c2%b0-any-angle\/"},"modified":"2007-05-12T16:13:48","modified_gmt":"2007-05-12T14:13:48","slug":"bitmaps-rotate-image-90%c2%b0-any-angle","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/bitmaps-rotate-image-90%c2%b0-any-angle\/","title":{"rendered":"Bitmaps: Rotate Image (90\u00b0, any angle)"},"content":{"rendered":"<p>Tony Nixon heeft geschreven in bericht<br \/>\n36645B68.102BFAE0@eng.monash.edu.au <\/p>\n<p><em>>&#8230;<br \/>\n>Hi all,<br \/>\n><br \/>\n>Could someone help me with a method of rotating a TBitmap image 180<br \/>\n>degrees.<br \/>\n><br \/>\n>TIA<br \/>\n><br \/>\n>Tony<br \/>\n<\/em><br \/>\n<!--more--><br \/>\nVon: Stefan Cruysberghs<br \/>\nBetreff: Re: Image Rotate<br \/>\nDatum: Samstag, 5. Dezember 1998 19:01 The following function I wrote rotates a bitmap 90\u00b0 to the left.<\/p>\n<p>[code lang=&#8221;delphi&#8221;]function SCRotateLeftBitmap(Bitmap : TBitmap) : TBitmap;<br \/>\nvar<br \/>\n  x,y : Integer;<br \/>\n  Hoogte, Breedte : Integer;<br \/>\nbegin<br \/>\n  Breedte:=Bitmap.Width;<br \/>\n  Hoogte:=Bitmap.Height;<br \/>\n  Result := TBitmap.Create;<br \/>\n  try<br \/>\n    with Result do<br \/>\n    begin<br \/>\n      Width:=Hoogte;<br \/>\n      Height:=Breedte;<br \/>\n      for x:=0 to Breedte-1 do<br \/>\n        for y:=0 to Hoogte-1 do<br \/>\n          Canvas.Pixels[Hoogte-y-1,x]:=Bitmap.Canvas.Pixels[x,y];<br \/>\n    end;<br \/>\n  except<br \/>\n    Result.Free;<br \/>\n    raise;<br \/>\n  end;<br \/>\nend;<br \/>\n[\/code]<br \/>\nThe next function rotates a bitmap with every angle, but I never tested it.<\/p>\n<p>[code lang=&#8221;delphi&#8221;]function RotateImage(Src : TBitmap; Anglo : Real) : TBitmap;<br \/>\nvar<br \/>\n i, j, W, H : Integer;<br \/>\n  X1, X2, Y1, Y2 : Integer;<br \/>\n  C : TColor;<br \/>\n  Rx, Ry : Integer;<br \/>\n  Side3, FX, FY : Extended;<br \/>\n  SDC, DDC : Integer;<br \/>\nbegin<br \/>\n  W := Src.Width;<br \/>\n  H := Src.Height;<br \/>\n TmpMem.Height := Round(H * 2.5);<br \/>\n TmpMem.Width := Round(W * 2.5);<br \/>\n  SDC := Src.Canvas.Handle;<br \/>\n  DDC := TmpMem.Canvas.Handle;<br \/>\n  for i := 0 to W &#8211; 1 do<br \/>\n   for j := 0 to H &#8211; 1 do<br \/>\n    begin<br \/>\n        C := GetPixel(SDC, i, j);<br \/>\n        Side3 := Sqrt(Sqr(i) + Sqr(j));<br \/>\n        SinCos((ArcSin(I \/ Side3) + Anglo), FX, FY);<br \/>\n        Rx := Round(FX * Side3) + W;<br \/>\n        Ry := Round(FY * Side3) + H;<br \/>\n        if j = 1 then<br \/>\n         begin<br \/>\n       X1 := Rx;<br \/>\n          Y1 := Ry;<br \/>\n          X2 := Rx;<br \/>\n          Y2 := Ry;<br \/>\n          end<br \/>\n        else<br \/>\n          begin<br \/>\n           if Rx < X1 then X1 := Rx;\n          if Ry < Y1 then Y1 := Ry;\n          if Rx > X2 then X2 := Rx;<br \/>\n          if Ry > Y2 then Y2 := Ry;<br \/>\n          end;<br \/>\n        SetPixel(DDC, Rx , Ry, C);<br \/>\n        end;<br \/>\n  Result := TmpMem;<br \/>\nend;<br \/>\n[\/code]<br \/>\nGreetings<\/p>\n<p>Stefan Cruysberghs<br \/>\nstefancr@mail.dma.be <\/p>\n<p>www.bewoner.dma.be\/stefancr<\/p>\n<p>[tags]Delphi, Graphic[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tony Nixon heeft geschreven in bericht 36645B68.102BFAE0@eng.monash.edu.au >&#8230; >Hi all, > >Could someone help me with a method of rotating a TBitmap image&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-2p","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/149"}],"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=149"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/149\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}