卷起千堆雪tyn:我帮你试了好久。
效果还是不行,我旋转一个10m的图像要40多秒。
Photoshop只要5秒。不知你为何要旋转图像?
先贴上刚做完的代码吧,还帮你试试
procedure RotateImage(SrcFile, DstFile: String;
Angle: Integer; BColor: TColor; hPb: Integer);
const
PI=3.1415926;
var
r1, c1: Integer;
r2, c2: Integer;//raw and col control variable
w1, h1: Integer;
w2, h2: Integer;//width and height variable
x1, y1: Double;
x2, y2: Double;//coordinate
cn, sn: Double;
Radian: Double;
Colour: TColor;
SrcBitmap: TBitmap;
DstBitmap: TBitmap;
begin
if not FileExists(SrcFile) then Exit;
SrcBitmap := TBitmap.Create;
try SrcBitmap.LoadFromFile(SrcFile);
except SrcBitmap.Free; Exit; end;
//Calculate radian
Radian := Angle/180*PI;
//Calculate cos(a) and sin(a)
cn := Cos(Radian);
sn := Sin(Radian);
w1 := SrcBitmap.Width;
h1 := SrcBitmap.Height;
//Calculate new height and new width
w2 := Round(Abs(w1*cn)+Abs(h1*sn));
h2 := Round(Abs(w1*sn)+Abs(h1*cn));
//Prepare to show progress
SendMessage(hPB,PBM_SETRANGE,0,h2 shl 16);
SendMessage(hPB,PBM_SETPOS,0,0);
//Create a new bitmap
DstBitmap := TBitmap.Create;
DstBitmap.Width := w2;
DstBitmap.Height := h2;
for r2 := 0 to h2-1 do
begin
for c2 := 0 to w2-1 do
begin
x2 := c2 - w2/2;
y2 := r2 - h2/2;
x1 := x2*cn+y2*sn;
y1 :=-x2*sn+y2*cn;
c1 := Round(x1+w1/2);
r1 := Round(y1+h1/2);
if (c1 >= 0) and (c1 < w1) and (r1 >= 0) and ( r1 < h1 ) then
Colour := SrcBitmap.Canvas.Pixels[c1,r1]//插值自己做吧
else
Colour := BColor;
DstBitmap.Canvas.Pixels[c2,r2] := Colour;
end;
SendMessage(hPB,PBM_SETPOS,r2+1,0);
end;
DstBitmap.SaveToFile(DstFile);
SrcBitmap.Free;
DstBitmap.Free;
end;