如何在一个在FORM里的IMAGE里实现,鼠标任意移动到屏幕的某个位置 ,以鼠标指针为中心点的自定义边长的一个矩形筐,时时抓取矩形内屏幕图像到IMAGE中?

解决方案 »

  1.   

    用mouseondown和mouseonup记录下两个角的坐标,然后用CopyRect来截取这部分image
      

  2.   

    用mouseondown和mouseonup记录下两个角的坐标,然后用CopyRect来截取这部分image一楼的就不费事呀,还要别人的代码干吗
      

  3.   

    如何把截取的图像在IMAGE中2倍显示
      

  4.   

    procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
       var
       R1: TRect;
      R2: TRect;
    begin
      R2.Left:=x-35;
      R2.Top:=y-35;
      R2.Right:=x+35;
      R2.Bottom:=y+35;  R1.Left:=0;
      R1.Top:=0;
      R1.Right:=70;
      R1.Bottom:=70;
      Image2.Canvas.CopyRect(R1,Image1.Canvas,R2)
    end;
      

  5.   

    Allanlove(山上的红叶疯了) 
    不行啊    在IMAGE里面只有白色的筐   我在timer里写的 x,y坐标我都有 
    我想时时随着鼠标指针的移动 IMAGE里也跟着变
      

  6.   

    什么意思
    随鼠标动,可以写到onMouseMove里面啊
    白色的筐?加张图片试试?
      

  7.   

    private
        Mo:integer;  //全局变量,记录指针是否按下procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
       var
       R1: TRect;
      R2: TRect;
    begin
      if mo=1 then
      begin
        R2.Left:=x-35;
        R2.Top:=y-35;
        R2.Right:=x+35;
        R2.Bottom:=y+35;    R1.Left:=0;
        R1.Top:=0;
        R1.Right:=70;
        R1.Bottom:=70;
        form1.Canvas.CopyRect(R1,Image1.Canvas,R2)
      end;
    end;procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      mo:=1;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      mo:=0;
    end;procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      mo:=0;
    end;
      

  8.   

    取得是Image1的图片,Image1里放一张bmp图片,jpg不好使
      

  9.   

    可能你还没明白我得意思
    已知鼠标在屏幕上得X,Y,在IMAGE中实现以鼠标指针为中心点的自定义边长的一个矩形筐,时时抓取矩形内屏幕图像到IMAGE中
    重点:不能在MOUSEMOVE中写 因为这只能局限在IMAGE中
      

  10.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
      TForm1 = class(TForm)
        Image1: TImage;
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
      function LowLevelKeyboardFunc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
    const   WH_MOUSE_LL=14;
    var
      Form1: TForm1;
      hkNTKeyboard: HHOOK;implementation{$R *.dfm}{ TForm1 }
    function LowLevelKeyboardFunc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;var 
       cav:Tcanvas;
       dc:HDC;
       p:Tpoint;
       i,j:integer;
       rectdest,rectSource:TRect;
    begin
     if ncode<>0 then
     begin
      Result:=CallNextHookEx(0, nCode, wParam, lParam);
      exit;
     end; case wParam of
       WM_MOUSEMOVE:
       begin  dc:=GetDc(0);
      cav:=Tcanvas.Create;
      cav.Handle:=dc;
      Getcursorpos(p);
      rectsource.Top:=p.y-30;
      rectsource.Left:=p.X-30;
      rectsource.Right:=p.X+30;
      rectsource.Bottom:=p.Y+30;
      rectdest.Top:=0;
      rectdest.Left:=0;
      rectdest.Right:=60;
      rectdest.Bottom:=60;
      Form1.Image1.Canvas.CopyRect(rectdest,cav,rectsource);
       end;
      end;
      Result:=CallNextHookEx(0, nCode, wParam, lParam);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
     hkNTKeyboard:=SetWindowsHookEx(WH_MOUSE_LL, LowLevelKeyboardFunc, HInstance, 0);
    end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      UnHookWindowsHookEx(hkNTKeyboard);end;end.
      

  11.   

    procedure ManipulateControl(Control: TControl; Move,Size:boolean;Shift: TShiftState; X, Y, Precision: integer);
    var
      SC_MANIPULATE: Word;
    begin
      if (X<=Precision) and (Y>Precision) and (Y<Control.Height-Precision) and (Size) then
      begin
        SC_MANIPULATE  := $F001;
        Control.Cursor := crSizeWE;
      end
      else if (X>=Control.Width-Precision) and (Y>Precision) and (Y<Control.Height-Precision) and (Size) then
      begin
        SC_MANIPULATE  := $F002;
        Control.Cursor := crSizeWE;
      end
      else if (X>Precision) and (X<Control.Width-Precision) and (Y<=Precision) and (Size) then
      begin
        SC_MANIPULATE  := $F003;
        Control.Cursor := crSizeNS;
      end
      else if (X<=Precision) and (Y<=Precision) and (Size) then
      begin
        SC_MANIPULATE  := $F004;
        Control.Cursor := crSizeNWSE;
      end
      else if (X>=Control.Width-Precision) and (Y<=Precision) and (Size) then
      begin
        SC_MANIPULATE  := $F005;
        Control.Cursor := crSizeNESW;
      end
      else if (X>Precision) and (X<Control.Width-Precision) and (Y>=Control.Height-Precision) and (Size) then
      begin
        SC_MANIPULATE  := $F006;
        Control.Cursor := crSizeNS;
      end
      else if (X<=Precision) and (Y>=Control.Height-Precision) and (Size) then
      begin
        SC_MANIPULATE  := $F007;
        Control.Cursor := crSizeNESW;
      end
      else if (X>=Control.Width-Precision) and (Y>=Control.Height-Precision) and (Size) then
      begin
        SC_MANIPULATE  := $F008;
        Control.Cursor := crSizeNWSE;
      end
      else if (X>5) and (Y>5) and (X<Control.Width-5) and (Y<Control.Height-5) and (Move) then
      begin
        SC_MANIPULATE  := $F009;
        Control.Cursor := crSizeAll;
      end
      else
      begin
        SC_MANIPULATE := $F000;
        Control.Cursor := crDefault;
      end;
      if Shift=[ssLeft] then
      begin
        ReleaseCapture;
        Control.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);
      end;
    end;procedure TForm3.TheImageMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      with Form1 do
        if ButtonToolIndex=0 then
          ManipulateControl((Sender as TControl),True,False,Shift, X, Y, 10)
        else
          TControl(Sender).Cursor := crDefault;
    end;