图片比Timage控件大,装载时缺省是显示左上角,怎样才能显示指定区域?多谢

解决方案 »

  1.   

    用Canvas.CopyRect将指定区域画上去
      

  2.   


    procedure TForm1.Button1Click(Sender: TObject);
    var
      Bmp1, Bmp2: TBitmap;
      Ra, Rb : TRect;
    begin
      Ra := Rect(30,30,Self.Image1.Width+30,Self.Image1.Height+30);
      Rb := Rect(0,0,Self.Image1.Width,Self.Image1.Height);
      Bmp1 := TBitmap.Create;
      Bmp2 := TBitmap.Create;
      Bmp2.Height := Image1.Height;
      Bmp2.Width  := Image1.Width;
      Bmp1.LoadFromFile('c:\a001.bmp');
      Bmp2.Canvas.CopyRect(Rb, Bmp1.Canvas, Ra);
      Image1.Picture.Bitmap.Assign(Bmp2);
      Bmp1.Free;
      Bmp2.Free;
    end;
      

  3.   

    用copyrect可放在任何位置:
    var
      Bitmap: TBitmap;
      MyRect, MyOther: TRect;
    begin  MyRect := Rect(0,0,100,100);  MyOther := Rect(20,20,100, 201);
      Bitmap := TBitmap.Create;
      Bitmap.LoadFromFile('c:\windows\tartan.bmp');
      Image1.Canvas.CopyRect(MyOther,Bitmap.Canvas,MyRect);
      Bitmap.Free;
    end;