(1)请问如何实现:鼠标按一下把图片点起随着鼠标移动 ,再点一下放下载鼠标的位置?
(2) 怎样实现任意角度旋转图片?
谢谢!

解决方案 »

  1.   

    找到别人的一点资料,贴上给你看看
    procedure ImageRF(const Bitmap:TBitmap;Angle:Integer;HVtype:Integer);
    var
      i,j:Integer;
      rowIn,rowOut:pRGBTriple;
      Bmp:TBitmap;
      Width,Height:Integer;
    begin
      Bmp:=TBitmap.Create;
      if (Angle=90) or (Angle=270) then
      begin
        Bmp.Width := Bitmap.Height;
        Bmp.Height := Bitmap.Width;
      end
      else
      begin
        Bmp.Width := Bitmap.Width;
        Bmp.Height := Bitmap.Height;
      end;
      Width:=Bitmap.Width-1;
      Height:=Bitmap.Height-1;
      if Bitmap.PixelFormat<>pf32Bit then Bitmap.PixelFormat:=pf24Bit;
      Bmp.PixelFormat:=Bitmap.PixelFormat;
      for  j := 0 to Height do
      begin
        rowIn  := Bitmap.ScanLine[j];
        for i := 0 to Width do
        begin
          if Angle=90 then
          begin
            rowOut := Bmp.ScanLine[i];
            Inc(rowOut,Height - j);
          end
          else if Angle=270 then
          begin
            rowOut := Bmp.ScanLine[Width - i];
            Inc(rowOut,j);
          end
          else if HVType=0 then
          begin
            rowOut := Bmp.ScanLine[j];
            Inc(rowOut,Width - i);
          end
          else if HVType=1 then
          begin
            rowOut := Bmp.ScanLine[Height - j];
            Inc(rowOut,i);
          end
          else
          begin
            rowOut := Bmp.ScanLine[Height - j];
            Inc(rowOut,Width - i);
          end;
          rowOut^ := rowIn^;
          Inc(rowIn);
        end;
      end;
      Bitmap.Assign(Bmp);
    end;function RotateBitmap(Bitmap:TBitmap;Angle:Integer;BackColor:TColor):TBitmap;
    var
      i,j,iOriginal,jOriginal,CosPoint,SinPoint : integer;
      RowOriginal,RowRotated : pRGBTriple;
      SinTheta,CosTheta : Extended;
      AngleAdd : integer;
    begin
      Bitmap.PixelFormat := pf24Bit;
      Result:=TBitmap.Create;
      Result.PixelFormat := pf24bit;
      Result.Canvas.Brush.Color:=BackColor;
      Angle:=Angle Mod 360;
      if Angle<0 then Angle:=360-Abs(Angle);
      if Angle=0 then
        Result.Assign(Bitmap)
      else if Angle=90 then
      begin
        Result.Assign(Bitmap);
        ImageRF(Result,90,-1);
      end
      else if (Angle>90) and (Angle<180) then
      begin
        AngleAdd:=90;
        Angle:=Angle-AngleAdd;
      end
      else if Angle=180 then
      begin
        Result.Assign(Bitmap);
        ImageRF(Result,180,-1);
      end
      else if (Angle>180) and (Angle<270) then
      begin
        AngleAdd:=180;
        Angle:=Angle-AngleAdd;
      end
      else if Angle=270 then
      begin
        Result.Assign(Bitmap);
        ImageRF(Result,270,-1);
      end
      else if (Angle>270) and (Angle<360) then
      begin
        AngleAdd:=270;
        Angle:=Angle-AngleAdd;
      end
      else
        AngleAdd:=0;
      if (Angle>0) and (Angle<90) then
      begin
      SinCos((Angle + AngleAdd) * Pi / 180, SinTheta, CosTheta);
      if (SinTheta * CosTheta) < 0 then
      begin
        Result.Width := Round(Abs(Bitmap.Width * CosTheta - Bitmap.Height * SinTheta));
        Result.Height := Round(Abs(Bitmap.Width * SinTheta - Bitmap.Height * CosTheta));
      end
      else
      begin
        Result.Width := Round(Abs(Bitmap.Width * CosTheta + Bitmap.Height * SinTheta));
        Result.Height := Round(Abs(Bitmap.Width * SinTheta + Bitmap.Height * CosTheta));
      end;
      CosTheta:=Abs(CosTheta);
      SinTheta:=Abs(SinTheta);
      if (AngleAdd=0) or (AngleAdd=180) then
      begin
        CosPoint:=Round(Bitmap.Height*CosTheta);
        SinPoint:=Round(Bitmap.Height*SinTheta);
      end
      else
      begin
        SinPoint:=Round(Bitmap.Width*CosTheta);
        CosPoint:=Round(Bitmap.Width*SinTheta);
      end;
      for j := 0 to Result.Height-1 do
      begin
        RowRotated := Result.Scanline[j];
        for i := 0 to Result.Width-1 do
        begin
          Case AngleAdd of
            0:
            begin
              jOriginal := Round((j+1-(i+1-SinPoint)*SinTheta/CosTheta)*CosTheta)-1;
              iOriginal := Round((i+1-(CosPoint-j-1)*SinTheta/CosTheta)*CosTheta)-1;
            end;
            90:
            begin
              iOriginal := Round((j+1-(i+1-SinPoint)/SinTheta*CosTheta)*SinTheta)-1;
              jOriginal := Bitmap.Height-Round((i+1-(CosPoint-j-1)/SinTheta*CosTheta)*SinTheta);
            end;
            180:
            begin
              jOriginal := Bitmap.Height-Round((j+1-(i+1-SinPoint)*SinTheta/CosTheta)*CosTheta);
              iOriginal := Bitmap.Width-Round((i+1-(CosPoint-j-1)*SinTheta/CosTheta)*CosTheta);
            end;
            270:
            begin
              iOriginal := Bitmap.Width-Round((j+1-(i+1-SinPoint)/SinTheta*CosTheta)*SinTheta);
              jOriginal := Round((i+1-(CosPoint-j-1)/SinTheta*CosTheta)*SinTheta)-1;
            end;
          end;
          if (iOriginal >= 0) and (iOriginal <= Bitmap.Width-1)and
             (jOriginal >= 0) and (jOriginal <= Bitmap.Height-1)
          then
          begin
            RowOriginal := Bitmap.Scanline[jOriginal];
            Inc(RowOriginal,iOriginal);
            RowRotated^ := RowOriginal^;
            Inc(RowRotated);
          end
          else
          begin
            Inc(RowRotated);
          end;
        end;
      end;
      end;
    end;