原理: 三角函数 平面转换
用例: 预估旋转后的位置, 可事先设定好矩形大小
代码:
var
angle: Single;
Sn, Cn: Single;
Sx, Sy, Scale: Single;
begin
angle:= angle* PI / 180; //180 - 负180度
// get the width and height of rotated image (without scaling)
SinCos(angle, Sn, Cn);
Sx := Abs(SrcR * Cn) + Abs(SrcB * Sn);
Sy := Abs(SrcR * Sn) + Abs(SrcB * Cn);
Panel1.Width := Trunc(sx); Panel1.Height :=Trunc(sy);
//居中
Panel1.Left := Dst.Left + (Dst.Width - Panel1.Width) div 2; Panel1.Top := Dst.Top + (Dst.Height - Panel1.Height) div 2;
// calculate a new scale so that the image fits in original boundaries
Sx := Src.Bitmap.Width / Sx;
Sy := Src.Bitmap.Height / Sy;
Scale := Min(Sx, Sy);
//缩放显示,保证display不超过src范围 T.Scale(Scale);
end;