// 欲旋转的图形 绕某点旋转 角度
procedure RotateBmp(BMP: TBitmap; CenterXY: TPoint; Angle: Double);
var
TmpBMP: TBitmap;
i, j, x, y, CenterX,CenterY, W, H: Integer;
SinV, CosV: Double;
px,py:Integer;
pf:Integer;
ps
IntegerArray;
begin
pf:=Integer(BMP.PixelFormat);
BMP.PixelFormat:=pf32bit;
SinV := Sin(-Angle*pi/180);
CosV := Cos(-Angle*pi/180);
TmpBMP := TBitmap.Create;
TmpBMP.Assign(BMP);
W:=BMP.Width; H:=BMP.Height;
BMP.Canvas.FillRect(Rect(0,0,W-1,H-1));
CenterX:=CenterXY.X; CenterY:=CenterXY.Y;
for i := 0 to H-1 do
begin
ps := TmpBMP.Scanline
;
py := i - CenterY;
for j := 0 to W-1 do
begin
px := j - CenterX;
x := Round(px * CosV - py * SinV) + CenterX;
y := Round(px * SinV + py * CosV) + CenterY;
if (x<0) or (x>=W) or (y<0) or (y>=H) then Continue;
PIntegerArray(BMP.ScanLine[y])[x]:=ps[j];
end;
end;
BMP.PixelFormat:=TPixelFormat(pf);
end;
请注意旋转将不可避免失真,因此您应该一次旋转到位。