//上面的是旋转任意角度
//这个是顺时针90度
procedure RotateClockwise(FBitmap: TBitmap);
{ rotate the FBitmap 90 deg clockwisely
bitmap size will change }
var
x, y: integer;
RowSrc, RowDest: PRGBArray;
Bmp:TBitmap;
begin
Bmp := TBitmap.Create; {create a temp. bitmap}
try
Bmp.Assign(FBitmap); {copy exactly from the internal bitmap}
FBitmap.Width := Height;
FBitmap.Height := Width; {change the size}
FWidth := FBitmap.Width;
FHeight := FBitmap.Height; {update width and height info}
for y := 0 to Bmp.Height - 1 do
begin
RowSrc := Bmp.ScanLine[y]; {scan every line of the source bitmap}
for x := 0 to Bmp.Width - 1 do
begin
RowDest := FBitmap.ScanLine[x];
with RowDest[Bmp.Height - 1 - y] do
begin
rgbtRed := RowSrc[x].rgbtRed;
rgbtGreen := RowSrc[x].rgbtGreen;
rgbtBlue := RowSrc[x].rgbtBlue;
end; {end of with}
{get RGB for destination bitmap i.e. the internal bitmap}
{eg: assum original width = 10, height = 5;
then resultant width = 5, height = 10;
Src Dest
[0, 0] [4, 0]
[2, 3] [1, 2]
in general,
[x, y] [5 - 1 - y, x] }
end;
end;
finally
Bmp.Free;
end;
end;
//这个是逆时针90度
procedure RotateCounterClockwise(FBitmap: TBitmap);
{ rotate FBitmap 90 deg counter-clockwisely
bitmap size will change }
var
x, y: integer;
RowSrc, RowDest: PRGBArray;
Bmp:TBitmap;
begin
Bmp := TBitmap.Create; {create a temp. bitmap}
try
Bmp.Assign(FBitmap); {copy exactly from the internal bitmap}
FBitmap.Width := Height;
FBitmap.Height := Width; {change the size}
FWidth := FBitmap.Width;
FHeight := FBitmap.Height; {update width and height info}
for y := 0 to Bmp.Height - 1 do
begin
RowSrc := Bmp.ScanLine[y]; {scan every line of the source bitmap}
for x := 0 to Bmp.Width - 1 do
begin
RowDest := FBitmap.ScanLine[Bmp.Width - 1 - x];
With RowDest[y] do
begin
rgbtRed := RowSrc[x].rgbtRed;
rgbtGreen := RowSrc[x].rgbtGreen;
rgbtBlue := RowSrc[x].rgbtBlue;
end; {end of with}
{get RGB for destination bitmap i.e. the internal bitmap}
{eg: assum original width = 10, height = 5;
then resultant width = 5, height = 10;
Src Dest
[0, 0] [9, 0]
[2, 3] [3, 7]
in general,
[x, y] [y, 10 - 1 - x] }
end;
end;
finally
Bmp.Free;
end;
end;