Mastodon
Programmierung

Bitmaps: Rotate Image (90°, any angle)

Tony Nixon heeft geschreven in bericht
36645B68.102BFAE0@eng.monash.edu.au

>…
>Hi all,
>
>Could someone help me with a method of rotating a TBitmap image 180
>degrees.
>
>TIA
>
>Tony


Von: Stefan Cruysberghs
Betreff: Re: Image Rotate
Datum: Samstag, 5. Dezember 1998 19:01 The following function I wrote rotates a bitmap 90° to the left.

[code lang=”delphi”]function SCRotateLeftBitmap(Bitmap : TBitmap) : TBitmap;
var
x,y : Integer;
Hoogte, Breedte : Integer;
begin
Breedte:=Bitmap.Width;
Hoogte:=Bitmap.Height;
Result := TBitmap.Create;
try
with Result do
begin
Width:=Hoogte;
Height:=Breedte;
for x:=0 to Breedte-1 do
for y:=0 to Hoogte-1 do
Canvas.Pixels[Hoogte-y-1,x]:=Bitmap.Canvas.Pixels[x,y];
end;
except
Result.Free;
raise;
end;
end;
[/code]
The next function rotates a bitmap with every angle, but I never tested it.

[code lang=”delphi”]function RotateImage(Src : TBitmap; Anglo : Real) : TBitmap;
var
i, j, W, H : Integer;
X1, X2, Y1, Y2 : Integer;
C : TColor;
Rx, Ry : Integer;
Side3, FX, FY : Extended;
SDC, DDC : Integer;
begin
W := Src.Width;
H := Src.Height;
TmpMem.Height := Round(H * 2.5);
TmpMem.Width := Round(W * 2.5);
SDC := Src.Canvas.Handle;
DDC := TmpMem.Canvas.Handle;
for i := 0 to W – 1 do
for j := 0 to H – 1 do
begin
C := GetPixel(SDC, i, j);
Side3 := Sqrt(Sqr(i) + Sqr(j));
SinCos((ArcSin(I / Side3) + Anglo), FX, FY);
Rx := Round(FX * Side3) + W;
Ry := Round(FY * Side3) + H;
if j = 1 then
begin
X1 := Rx;
Y1 := Ry;
X2 := Rx;
Y2 := Ry;
end
else
begin
if Rx < X1 then X1 := Rx; if Ry < Y1 then Y1 := Ry; if Rx > X2 then X2 := Rx;
if Ry > Y2 then Y2 := Ry;
end;
SetPixel(DDC, Rx , Ry, C);
end;
Result := TmpMem;
end;
[/code]
Greetings

Stefan Cruysberghs
stefancr@mail.dma.be

www.bewoner.dma.be/stefancr

[tags]Delphi, Graphic[/tags]

0 Kommentare zu “Bitmaps: Rotate Image (90°, any angle)

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.