procedure RotateBmp(bmp: TBitmap; Center: TPoint; angle: Integer);
var
tmpbmp: TBitmap;
i, j, x, y, px, py: Integer;
cAngle, sAngle: extended;
p1, p2: Pchar;
begin
while angle < 0 do
angle := angle + 360;
angle := angle mod 360;
sAngle := sin(- angle * pi / 180);
cAngle := cos(- angle * pi / 180);
tmpbmp := tbitmap.create;
tmpbmp.assign(bmp);
for i := 0 to tmpbmp.height - 1 do
begin
p1 := pchar(tmpbmp.scanline);
py := 2 * (i - center.y) - 1;
for j := 0 to tmpbmp.width - 1 do
begin
px := 2 * (j - center.x) - 1;
x := (round(px * cAngle - py * sAngle) - 1) div 2 + center.x;
y := (round(px * sAngle + py * cAngle) - 1) div 2 + center.y;
if (x>=0) and (x<tmpbmp.width) and (y>=0) and (y<=tmpbmp.height) then
begin
p2 := pchar(bmp.scanline[y]) + x * 3;
move(p1^, p2^, 3);
end;
inc(p1, 3);
end;
end;
end;