各位老大,怎么取得摄象头的图象保存为图片,能不能贴一段代码上来呀,谢谢。

解决方案 »

  1.   

    如何在delphi中显示摄象投的内容并且抓取图片
    http://community.csdn.net/Expert/topic/3244/3244287.xml?temp=.4416925
      

  2.   

    unit UnitAviCap;interfaceuses Windows, Messages;const
      WM_CAP_START = WM_USER;
      
      WM_CAP_SET_CALLBACK_ERROR       = WM_CAP_START + 2;
      WM_CAP_SET_CALLBACK_STATUS      = WM_CAP_START + 3;
      WM_CAP_SET_CALLBACK_FRAME       = WM_CAP_START + 5;
      WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START + 6;
      WM_CAP_DRIVER_CONNECT           = WM_CAP_START + 10;
      WM_CAP_DRIVER_DISCONNECT        = WM_CAP_START + 11;
      WM_CAP_FILE_SET_CAPTURE_FILE    = WM_CAP_START + 20;
      WM_CAP_FILE_SAVEDIB             = WM_CAP_START + 25;
      WM_CAP_DLG_VIDEOSOURCE          = WM_CAP_START + 42;
      WM_CAP_SET_PREVIEW              = WM_CAP_START + 50;
      WM_CAP_SET_OVERLAY              = WM_CAP_START + 51;
      WM_CAP_SET_PREVIEWRATE          = WM_CAP_START + 52;
      WM_CAP_SET_SCALE                = WM_CAP_START + 53;
      WM_CAP_GRAB_FRAME               = WM_CAP_START + 60;
      WM_CAP_SEQUENCE                 = WM_CAP_START + 62;
      WM_CAP_SEQUENCE_NOFILE          = WM_CAP_START + 63;
      WM_CAP_STOP                     = WM_CAP_START + 68;function capCreateCaptureWindow(lpszWindowName: PChar; dwStyle: Longint; x: Integer;
      y: Integer; nWidth: Integer; nHeight: Integer; ParentWin: HWND;
      nId: Integer): HWND; stdcall;implementationfunction capCreateCaptureWindow; external 'AVICAP32.DLL' name 'capCreateCaptureWindowA';end.//实现
    //开始监视
    procedure TfrmMain.btn_PrevBeginClick(Sender: TObject);
    begin
      hWndC := capCreateCaptureWindow('', WS_CHILD or WS_VISIBLE , 40, 30, 320, 240, pal_Prev.Handle, 0);
      if hWndC <> 0 then
      begin
        SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);
        SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0);
        SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUS, 0, 0);
        SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
        SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0);
        SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0);
        SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0);
        SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0);
        btn_PrevBegin.Enabled := False;
        btn_PrevEnd.Enabled := True;
        btn_CatchBMP.Enabled := True;
        btn_RecBegin.Enabled := True;
      end;
    end;//停止监视
    procedure TfrmMain.btn_PrevEndClick(Sender: TObject);
    begin
      if hWndC <> 0 then begin
        SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
        hWndC := 0;
        btn_PrevBegin.Enabled := True;
        btn_PrevEnd.Enabled := False;
        btn_CatchBMP.Enabled := False;
        btn_RecBegin.Enabled := False;
      end;
    end;//抓图
    procedure TfrmMain.btn_CatchBMPClick(Sender: TObject);
    var
      FileName: string;
    begin
      if hWndC <> 0 then
      begin
        FileName := CurPath + '\' + FormatDateTime('HHMMSSZZZ', Now) + '.bmp';
        SendMessage(hWndC, WM_CAP_FILE_SAVEDIB, 0, Longint(PChar(FileName)));
        img_BMP.Picture.LoadFromFile(FileName);
        flstbox_BMP.Update;
        flstbox_BMP.Selected[flstbox_BMP.Items.Count-1] := True;
      end;
    end;//开始录像
    procedure TfrmMain.btn_RecBeginClick(Sender: TObject);
    begin
      if hWndC <> 0 then
        if sd_AVI.Execute then
        begin
          SendMessage(hWndC, WM_CAP_FILE_SET_CAPTURE_FILE, 0, Longint(PChar(sd_AVI.FileName)));
          SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0);
          btn_RecBegin.Enabled := False;
          btn_RecEnd.Enabled := True;
        end;
    end;//停止录像
    procedure TfrmMain.btn_RecEndClick(Sender: TObject);
    begin
      if hWndC <> 0 then
      begin
        SendMessage(hWndC, WM_CAP_STOP, 0, 0);
        btn_RecBegin.Enabled := True;
        btn_RecEnd.Enabled := False;
      end;
    end;
      

  3.   

    找imageen的控件 挺好用          
              ImageEnIO1.Acquire;
              // Sets colormapped 256 colors
              ImageEnIO1.Params.BitsPerSample:=1;
              ImageEnIO1.Params.SamplesPerPixel:=1;
              // Sets OS2.x compressed BMP
              ImageEnIO1.Params.BMP_Version:=ioBMP_BMOS2V2;
              ImageEnIO1.Params.BMP_Compression:=ioBMP_RLE;
              // Saves          ImageEnIO1.SaveToFile('a.bmp');