我是通过计算切点,但这样太太麻烦了,一大篇代码,还不能转....最好有点原码谢谢!!!!

解决方案 »

  1.   


    这样应该好些了:
    Graphics::TBitmap *TmpBmp = new Graphics::TBitmap();
    TmpBmp->Width = Image1->Height;
    TmpBmp->Height = Image1->Width;
    for(int i=0; i<TmpBmp->Height; i++)
    {
      for(int j=0; j<TmpBmp->Width; j++)
      {
        TmpBmp->Canvas->Pixels[j][i] =
          Image1->Picture->Bitmap->Canvas->Pixels[i][TmpBmp->Width-j-1];
      }
    }
    Image1->Width = TmpBmp->Width;
    Image1->Height = TmpBmp->Height;
    Image1->Picture->Bitmap->Assign(TmpBmp);
    delete TmpBmp;
    我用C++ builder遍的,旋转90度例子,如果你只要算法应该没问题
      

  2.   

    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;