用videocap控件作照片采集,想在视频窗口出现一矩形截图框,可拖动,截取框内的图像,怎么实现?

解决方案 »

  1.   

    以下代码用镂空窗口作一个框可以拖动unit SimpleF;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, ExtCtrls,ShellAPI, AppEvnts;
    const LWidth = 4;
          TrayIconID = 335;
    type
      TfmSimple = class(TForm)
        ApplicationEvents1: TApplicationEvents;
        procedure FormResize(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure ApplicationEvents1Deactivate(Sender: TObject);
      private
        procedure WmNCHitTest(var Msg : TWMNCHitTest); message WM_NCHITTEST;
        procedure WindowMove(var Msg: TMsg);message WM_MOVE;
      end;var
      fmSimple: TfmSimple;
      bTemp: Boolean = False;
      Nid: TNotifyIconData;
    implementationuses MainF;{$R *.DFM}procedure TfmSimple.WmNCHitTest(var Msg: TWMNCHitTest);
    const v=4; //border width
    var
      p:TPoint;
    begin
      Inherited;
      if NOT fmMain.panOperation.Enabled then Exit;  p:=Point(Msg.XPos,Msg.YPos);
      p:=ScreenToClient(p);  if PtInRect(Rect(0,0,v,v),p) then
      Msg.Result:=HTTOPLEFT  else if PtInRect(Rect(Width-v,Height-v,Width,Height),p) then
      Msg.Result:=HTBOTTOMRIGHT  else if PtInRect(Rect(Width-v,0,Width,v),p) then
      Msg.Result:=HTTOPRIGHT  else if PtInRect(Rect(0,Height-v,v,Height),p) then
      Msg.Result:=HTBOTTOMLEFT  else if PtInRect(Rect(v,0,Width-v,v),p) then
      Msg.Result:=HTTOP  else if PtInRect(Rect(0,v,v,Height-v),p) then
      Msg.Result:=HTLEFT  else if PtInRect(Rect(Width-v,v,Width,Height-v),p) then
      Msg.Result:=HTRIGHT  else if PtInRect(Rect(v,Height-v,Width-v,Height),p) then
      Msg.Result:=HTBOTTOM;  if PtInRect(Rect(LWidth,0,Width - LWidth,LWidth),p) then
      Msg.Result := HTCAPTION;end;procedure TfmSimple.FormResize(Sender: TObject);
    begin
      BeginPath(Canvas.handle);
      SetBkMode(Canvas.Handle,TRANSPARENT );
      canvas.Polygon([Point(0,0),Point(Width,0),
                        Point(Width,Height),Point(0,Height),
                        Point(0,0)]);
      Canvas.MoveTo(LWidth,LWidth);
      Canvas.LineTo(Width - LWidth,LWidth);
      Canvas.LineTo(Width -LWidth,Height -LWidth);
      Canvas.LineTo(LWidth,Height -LWidth);
      Canvas.LineTo(LWidth,LWidth);  EndPath(canvas.handle);  SetWindowRgn(Handle,PathToRegion(canvas.Handle), true );
    end;procedure TfmSimple.FormCreate(Sender: TObject);
    begin
      //限定窗口形关为一方框
      Canvas.Pen.Width := 1;
      BeginPath(canvas.handle);
        SetBkMode(Canvas.Handle,TRANSPARENT );
        canvas.Polygon([Point(0,0),Point(Width,0),
                        Point(Width,Height),Point(0,Height),
                        Point(0,0)]);
      Canvas.MoveTo(LWidth,LWidth);
      Canvas.LineTo(Width - LWidth,LWidth);
      Canvas.LineTo(Width -LWidth,Height -LWidth);
      Canvas.LineTo(LWidth,Height -LWidth);
      Canvas.LineTo(LWidth,LWidth);
      EndPath(canvas.handle);  SetWindowRgn(Handle,PathToRegion(canvas.Handle), true );
    end;procedure TfmSimple.WindowMove(var Msg: TMsg);
    begin
      inherited;
      BeginPath(Canvas.handle);
      SetBkMode(Canvas.Handle,TRANSPARENT );
      canvas.Polygon([Point(0,0),Point(Width,0),
                        Point(Width,Height),Point(0,Height),
                        Point(0,0)]);
      Canvas.MoveTo(LWidth,LWidth);
      Canvas.LineTo(Width - LWidth,LWidth);
      Canvas.LineTo(Width -LWidth,Height -LWidth);
      Canvas.LineTo(LWidth,Height -LWidth);
      Canvas.LineTo(LWidth,LWidth);
      EndPath(canvas.handle);
      SetWindowRgn(Handle,PathToRegion(canvas.Handle), true );
    end;
    end.
      

  2.   

    怎么会不能移动呢应该是你的PTINRECT这里的数字出了点问题吧