var
    i,j:integer;
    bmp1,bmp:TBitmap;
begin
.......
    bmp.Width:=bmp1.Height;
    bmp.Height:=bmp1.Width;
    for i:=0 to bmp1.Height-1 do
        for j:=0 to bmp1.Width-1 do
            //bmp.Canvas.Pixels[bmp.Width-i,j]:=bmp1.Canvas.Pixels[j,i];
            bmp.Canvas.Pixels[i,bmp.Height-j]:=bmp1.Canvas.Pixels[j,i];
可以把bmp1旋转为bmp(包括左转和右转),但循环太慢了,能否有简单的方法,比如有一个函数就可以完成,毕竟只是旋转90度,不需要用到三角函数。

解决方案 »

  1.   

    用Timgedit(柯达的)控件,在delphi里可以自己添加,有旋转的属性
      

  2.   

    我怎么找不到这些控件呀,没有activeX。
    循环很慢的,我的CPU1G,内存256M,转一张1024*768的图片要好十几秒,我能忍受客户也不能忍受(客户的机器只是赛扬300)。
    能否告诉下载地址,谢谢。
      

  3.   

    procedure rotate(sur:pchar;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:PFcolor;
    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即以图像的中心为旋转中心。此程序处理速度快,可处理大图片。
      

  4.   

    bmp_rotate(Image1.Picture.Bitmap, Image2.Picture.Bitmap, RAngle);procedure TfrmColor.bmp_rotate(src,dst:tbitmap;angle:extended);
    var
      c1x,c1y,c2x,c2y:integer;
      p1x,p1y,p2x,p2y:integer;
      radius,n:integer;
      alpha:extended;
      c0,c1,c2,c3:tcolor;
    begin
       //将角度转换为PI值
      angle := (angle / 180) * pi;
       // 计算中心点,你可以修改它
      c1x := src.width div 2;
      c1y := src.height div 2;
      c2x := dst.width div 2;
      c2y := dst.height div 2;      // 步骤数值number
      if c2x < c2y then
        n := c2y
      else
        n := c2x;
      dec (n,1);   // 开始旋转
      for p2x := 0 to n do begin
        for p2y := 0 to n do begin
          if p2x = 0 then
            alpha:= pi/2
          else
            alpha := arctan2(p2y,p2x);
          radius := round(sqrt((p2x*p2x)+(p2y*p2y)));
          p1x := round(radius * cos(angle+alpha));
          p1y := round(radius * sin(angle+alpha));
                 
          c0 := src.canvas.pixels[c1x+p1x,c1y+p1y];
          c1 := src.canvas.pixels[c1x-p1x,c1y-p1y];
          c2 := src.canvas.pixels[c1x+p1y,c1y-p1x];
          c3 := src.canvas.pixels[c1x-p1y,c1y+p1x];      dst.canvas.pixels[c2x+p2x,c2y+p2y]:=c0;
          dst.canvas.pixels[c2x-p2x,c2y-p2y]:=c1;
          dst.canvas.pixels[c2x+p2y,c2y-p2x]:=c2;
          dst.canvas.pixels[c2x-p2y,c2y+p2x]:=c3;
        end;
        application.processmessages
      end;
    end;