给你一段程序,给分:
procedure RotateWmf(AWmf: TMetaFile; const Angle: Double);
function CalAngle(PointX, PointY: Double): Double;
var
d1, d2, d3: Double;
begin
d1 := - PointX;
d2 := - PointY;
if d1 <> 0 then
begin
d3 := ArcTan(Abs(d2 / d1)) * 180 / PI;
if (d2 > 0) and (d1 < 0) then
d3 := 180 - d3
else if (d2 <= 0) and (d1 < 0) then
d3 := d3 + 180
else if (d2 < 0) and (d1 > 0) then
d3 := 360 - d3;
end
else
begin
if d2 > 0 then
d3 := 90
else if D2 < 0 then
d3 := 270
else
d3 := -1;
end;
Result := d3;
end;
var
d1, d2, d3, d4, d5, d6: Double;
pXf: XFORM;
RoMetafile: TMetafile;
RoMetafileCanvas: TMetafileCanvas;
R: TRect;
begin
if not Assigned(AWmf) or (Angle = 0) then
Exit;
if (AWmf.Width = 0) or
(AWmf.Height = 0) then
Exit;
with pXf do
begin
d3 := -Angle * PI / 180;
d1 := COS(d3);
d2 := SIN(d3);
eM11 := d1;
eM12 := d2;
eM21 := -d2;
eM22 := d1;
d4 := AWmf.Width / 2;
d5 := AWmf.Height / 2;
d3 :=CalAngle(d4, d5) -Angle;
d3 := -d3 * PI / 180;
d6 := sqrt(d4 * d4 + d5 * d5);
d1 := COS(d3) * d6 + d4;
d2 := -SIN(d3) * d6 + d5;
eDx := d1;
eDy := d2;
end;
RoMetafile := TMetafile.Create;
try
R := Rect(0, 0, AWmf.Width, AWmf.Height);
RoMetafile.Width := AWmf.Width;
RoMetafile.Height := AWmf.Height;
RoMetafileCanvas := TMetafileCanvas.Create(RoMetafile, 0);
try
SetGraphicsMode(AWmf.Handle, GM_COMPATIBLE);
SetGraphicsMode(RoMetafileCanvas.Handle, GM_ADVANCED);
SetWorldTransform(RoMetafileCanvas.Handle, pXf);
PlayEnhMetaFile(RoMetafileCanvas.Handle, AWmf.Handle, R);
finally
RoMetafileCanvas.Free;
end;
AWmf.Clear;
AWmf.Assign(RoMetafile);
finally
RoMetafile.Free;
end;
end;
//此程序有一个缺点:多用几次会越来越慢,不知为何