请问:如何将一副bmp图片旋转90度之后,通过savetofile保存后是旋转90度之后的结果?我用的是fcImager控件,里面有属性angle实现旋转效果,但保存之后仍然是旋转之前的图片。
我搜索过之前csdn的文章,有一篇文章说fcImager控件不行。用象素矩阵实现旋转可以,不过速度太慢了,不能接受。小弟初学delphi不久,希望有高手能指点一下小弟,小弟不胜感激!

解决方案 »

  1.   

    用TImage的Canvas进行逐点画,不过效率也很低。
      

  2.   

    用ScanLine处理是最快的
    Google上找例子吧http://lysoft.7u7.net
      

  3.   

    刚好,把这方面的东西整理了一下,
    点扫描的话,如果图片不大,还是不慢的 
    function TPic.AdjustPosition(Bmp, BmpDest: TBitmap; Angle: Double): integer;
    var
      i, j, iRotationAxis, iOriginal, iPrime, iPrimeRotated, jRotationAxis, jOriginal,
      jPrime, jPrimeRotated: Integer;
      RowOriginal: pRGBArray;
      RowRotated: pRGBArray;
      Theta, sinTheta, cosTheta: DOUBLE;
      R, G, B: byte;
      FColor: TColor;
      SavFormat: TPixelFormat;
    begin
    //最大程度保证不丢失图象  
      if bmp.Width>bmp.Height then
      begin
      BmpDest.Width := Bmp.Width;
      BmpDest.Height := Bmp.Width;
      end
      else
      begin
      BmpDest.Width := Bmp.height;
      BmpDest.Height := Bmp.height;
      end;
    //   BmpDest.PixelFormat := pf24bit;
      SavFormat := Bmp.PixelFormat;
      Bmp.PixelFormat := pf24bit;
      BmpDest.PixelFormat := Bmp.PixelFormat;
      iRotationAxis := Bmp.Width div 2;
      jRotationAxis := Bmp.Height div 2;
      Theta := Angle * PI / 180;
      sinTheta := SIN(Theta);
      cosTheta := COS(Theta);
      FColor := Bmp.Canvas.Pixels[0, 0];
      B := FColor mod 256;
      G := round((FColor div 256) mod 256);
      R := round((FColor div 256) div 256);  for j := BmpDest.Height - 1 downto 0 do
      begin
        RowRotated := BmpDest.Scanline[j];
        jPrime := 2 * (j - jRotationAxis) + 1;
        for i := BmpDest.Width - 1 downto 0 do
        begin
          iPrime := 2 * (i - iRotationAxis) + 1;
          iPrimeRotated := ROUND(iPrime * CosTheta - jPrime * sinTheta);
          jPrimeRotated := ROUND(iPrime * sinTheta + jPrime * cosTheta);
          iOriginal := (iPrimeRotated - 1) div 2 + iRotationAxis;
          jOriginal := (jPrimeRotated - 1) div 2 + jRotationAxis;
          if (iOriginal >= 0) and (iOriginal <= Bmp.Width - 1) and
            (jOriginal >= 0) and (jOriginal <= Bmp.Height - 1)
            then
          begin
            RowOriginal := Bmp.Scanline[jOriginal];
            RowRotated[i] := RowOriginal[iOriginal]
          end
          else
          begin
            RowRotated[i].rgbtBlue := B;
            RowRotated[i].rgbtGreen := G;
            RowRotated[i].rgbtRed := R
          end;
        end;
      end;
      Bmp.PixelFormat := SavFormat;
      BmpDest.PixelFormat := Bmp.PixelFormat;
      result:=1;
    end;procedure TForm1.N14Click(Sender: TObject);
    var
    bmpdest : TBitmap;
    begin
      bmp :=TBitmap.Create;
      bmpdest :=Tbitmap.Create;
      bmp.Assign(Image1.Picture.Bitmap);
      PicDeal.AdjustPosition(Bmp, bmpdest,90);
      form1.Image2.Picture.Bitmap.Assign(BmpDest);
      bmp.Free;
    end;
      

  4.   

    type
      pRGBArray = ^TRGBArray;
     {$EXTERNALSYM pRGBArray}
      TRGBArray = array[0..MaxPixelCount - 1] of TRGBTriple;
      

  5.   

    //针对32位色
    Bitmap.PixelFormat := pf32Bit;//调用
    Rotate90(Bitmap);PBGRA = ^TBGRA;
    TBGRA = packed record
      B, G, R, A: Byte;
    end;procedure Rotate90(const ABitmap: TBitmap);
    var
      I, J: Integer;
      RowIn, RowOut, POut: PBGRA;
      Bmp: TBitmap;
      Width, Height: Integer;
      LineSize: Integer;
    begin
      Bmp := TBitmap.Create;
      Bmp.Width := ABitmap.Height;
      Bmp.Height := ABitmap.Width;
      Bmp.PixelFormat := pf32Bit;
      Width := ABitmap.Width-1;
      Height := ABitmap.Height-1;
      LineSize := Bmp.Width;
      RowIn := ABitmap.ScanLine[Height];
      POut := PBGRA(Cardinal(Bmp.ScanLine[0]) - 4);
      for  j := 0 to Height do
      begin
        Inc(POut);
        RowOut := POut;
        for I := 0 to Width do
        begin
          RowOut^ := RowIn^;
          Inc(RowIn);
          Dec(RowOut, LineSize);
        end;
      end;
      ABitmap.Assign(Bmp);
      Bmp.Free;
    end;
      

  6.   

    晕,CSDN怎么把偶的代码弄这么丑~~~