我以前写的《JPEG、BMP等数字图像的快速处理(二)》的片断,在我的主页上
http://winprogram.yeah.net 的我的文章里有全文
procedure rotate(sur
char;bmp:Tbitmap;cx,cy:integer;angle:integer);
var
x1,y1,x3,y3 :integer //x1,y1 为平移坐标 x3,y3为旋转的新坐标
x,y,h,w,widthbytes,dst,v:integer;
hcos,hsin:double;
tmp
Fcolor;
hu:double;
begin
hu:=angle*3.1415/180;
hcos:=cos(hu); hsin:=sin(hu);
h:=bmp.Height; w:=bmp.Width ;
widthbytes:=integer(bmp.scanline[0])-integer(bmp.scanline[1]);
dst:=integer(bmp.ScanLine[h-1]);
fillchar(pchar(dst)^,widthbytes*h,0); //使图像全黑
for y:=0 to h-1 do
begin
y1:=y -(h-cy); //平移下的y
for x:=0 to W-1 do
begin
x1:=x-cx; //平移下的x
x3:=round(x1*hcos-y1*hsin);
y3:=round(x1*hsin+y1*hcos); //平移下的新坐标
x3:=x3+cx;
y3:=y3+(h-cy); //转换回原坐标
if (x3>=0) and (x3<w-1) and (y3>=0) and (y3<h-1) then
pfcolor(dst+x*3+y*widthbytes)^:=
pfcolor(integer(sur)+x3*3+y3*widthbytes)^;
end;
end;
end;
angle为旋转的角度,cx、cy为旋转中心, cx=width div 2,cy=height div 2即以图像的中心为旋转中心。此程序处理速度快,可处理大图片。