L
Lee_Bee
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Bmp_Rotate(Src, Dst: TBitmap; Angle: Extended);
var
C1X, C1Y, C2X, C2Y: Integer;
P1X, P1Y, P2X, P2Y: Integer;
Radius, N, Diff: Integer;
Alpha: Extended;
//C0, C1, C2, C3: TColor;
begin
//angle为旋转的角度,cx、cy为旋转中心, cx=width div 2,cy=height div 2即以图像的中心为旋转中心。
//Dst.Width := Dst.Width + 60;
//Dst.Height := Dst.Height + 40;
Angle := Angle * Pi / 180; //旋转角度
C1X := Src.Width div 2; //图像的中心为旋转中心
C1Y := Src.Height div 2;
C2X := Dst.Width div 2;
C2Y := Dst.Height div 2;
if C2X < C2Y then N := C2Y
else
N := C2X;
for P2X := 0 to N - 1 do begin
for P2Y := 0 to N - 1 do begin
if P2X = 0 then Alpha := Pi/2
else
Alpha := Arctan2(P2Y, P2X); // Alpha=P2Y/P2X
Radius := Round(Sqrt((P2X * P2X) + (P2Y * P2Y))); //设置旋转时半径大小
P1X := Round(Radius * Cos(Angle + Alpha)); //设置旋转时圆心横坐标
P1Y := Round(Radius * Sin(Angle + Alpha)); //设置旋转时圆心纵坐标
Dst.Canvas.Pixels[C2X + P2X, C2Y + P2Y] := Src.Canvas.Pixels[C1X + P1X, C1Y + P1Y]; //替换不同位置像素点 替换图象相关坐标处像素
Dst.Canvas.Pixels[C2X - P2X, C2Y - P2Y] := Src.Canvas.Pixels[C1X - P1X, C1Y - P1Y];
Dst.Canvas.Pixels[C2X + P2Y, C2Y - P2X] := Src.Canvas.Pixels[C1X + P1Y, C1Y - P1X]; //
Dst.Canvas.Pixels[C2X - P2Y, C2Y + P2X] := Src.Canvas.Pixels[C1X - P1Y, C1Y + P1X];
end;
end;
Application.ProcessMessages;
end;
var
C1X, C1Y, C2X, C2Y: Integer;
P1X, P1Y, P2X, P2Y: Integer;
Radius, N, Diff: Integer;
Alpha: Extended;
//C0, C1, C2, C3: TColor;
begin
//angle为旋转的角度,cx、cy为旋转中心, cx=width div 2,cy=height div 2即以图像的中心为旋转中心。
//Dst.Width := Dst.Width + 60;
//Dst.Height := Dst.Height + 40;
Angle := Angle * Pi / 180; //旋转角度
C1X := Src.Width div 2; //图像的中心为旋转中心
C1Y := Src.Height div 2;
C2X := Dst.Width div 2;
C2Y := Dst.Height div 2;
if C2X < C2Y then N := C2Y
else
N := C2X;
for P2X := 0 to N - 1 do begin
for P2Y := 0 to N - 1 do begin
if P2X = 0 then Alpha := Pi/2
else
Alpha := Arctan2(P2Y, P2X); // Alpha=P2Y/P2X
Radius := Round(Sqrt((P2X * P2X) + (P2Y * P2Y))); //设置旋转时半径大小
P1X := Round(Radius * Cos(Angle + Alpha)); //设置旋转时圆心横坐标
P1Y := Round(Radius * Sin(Angle + Alpha)); //设置旋转时圆心纵坐标
Dst.Canvas.Pixels[C2X + P2X, C2Y + P2Y] := Src.Canvas.Pixels[C1X + P1X, C1Y + P1Y]; //替换不同位置像素点 替换图象相关坐标处像素
Dst.Canvas.Pixels[C2X - P2X, C2Y - P2Y] := Src.Canvas.Pixels[C1X - P1X, C1Y - P1Y];
Dst.Canvas.Pixels[C2X + P2Y, C2Y - P2X] := Src.Canvas.Pixels[C1X + P1Y, C1Y - P1X]; //
Dst.Canvas.Pixels[C2X - P2Y, C2Y + P2X] := Src.Canvas.Pixels[C1X - P1Y, C1Y + P1X];
end;
end;
Application.ProcessMessages;
end;