熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Delphi編程 >> 正文

利用Delphi編輯控制攝像頭(二)

2013-11-23 17:34:52  來源: Delphi編程 
    完整的程序代碼如下

    unit Unit;
    interface
    uses
    Windows Messages SysUtils Variants Classes Graphics Controls Forms
    Dialogs StdCtrls ExtCtrls;
    type
    TForm = class(TForm)
    Panel: TPanel;
    Button: TButton;
    Button: TButton;
    Button: TButton;
    Button: TButton;
    Button: TButton;
    procedure ButtonClick(Sender: TObject);
    procedure ButtonClick(Sender: TObject);
    procedure ButtonClick(Sender: TObject);
    procedure ButtonClick(Sender: TObject);
    procedure ButtonClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    private
    hWndC : THandle;
    public
    { Public declarations }
    end;
    var
    Form: TForm;
    const WM_CAP_START = WM_USER;
    const WM_CAP_STOP = WM_CAP_START + ;
    const WM_CAP_DRIVER_CONNECT = WM_CAP_START + ;
    const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + ;
    const WM_CAP_SAVEDIB = WM_CAP_START + ;
    const WM_CAP_GRAB_FRAME = WM_CAP_START + ;
    const WM_CAP_SEQUENCE = WM_CAP_START + ;
    const WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + ;
    const WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+
    const WM_CAP_SET_OVERLAY =WM_CAP_START+
    const WM_CAP_SET_PREVIEW =WM_CAP_START+
    const WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +;
    const WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +;
    const WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +;
    const WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +;
    const WM_CAP_SET_SCALE=WM_CAP_START+
    const WM_CAP_SET_PREVIEWRATE=WM_CAP_START+
    function capCreateCaptureWindowA(lpszWindowName : PCHAR;
    dwStyle : longint;x : integer;y : integer;nWidth : integer;
    nHeight : integer;ParentWin : HWND;nId : integer): HWND;
    STDCALL EXTERNAL AVICAPDLL;
    implementation
    {$R *dfm}
    procedure TFormButtonClick(Sender: TObject);
    begin
    hWndC := capCreateCaptureWindowA(My Own Capture WindowWS_CHILD or WS_VISIBLE PanelLeftPanelTopPanelWidthPanelHeightFormHandle);
    hWndC := capCreateCaptureWindowA(My Own Capture WindowWS_CHILD or WS_VISIBLE PanelLeftPanelTopPanelWidthPanelHeightFormHandle);
    if hWndC <> then
    begin
    SendMessage(hWndC WM_CAP_SET_CALLBACK_VIDEOSTREAM );
    SendMessage(hWndC WM_CAP_SET_CALLBACK_ERROR );
    SendMessage(hWndC WM_CAP_SET_CALLBACK_STATUSA );
    SendMessage(hWndC WM_CAP_DRIVER_CONNECT );
    SendMessage(hWndC WM_CAP_SET_SCALE );
    SendMessage(hWndC WM_CAP_SET_PREVIEWRATE );
    SendMessage(hWndC WM_CAP_SET_OVERLAY );
    SendMessage(hWndC WM_CAP_SET_PREVIEW );
    end;
    end;
    procedure TFormButtonClick(Sender: TObject);
    begin
    if hWndC <> then begin
    SendMessage(hWndC WM_CAP_DRIVER_DISCONNECT );
    hWndC := ;
    end;
    end;
    procedure TFormButtonClick(Sender: TObject);
    begin
    if hWndC <> then begin
    SendMessage(hWndCWM_CAP_SAVEDIBlongint(pchar(c:\testbmp)));
    end;
    end;
    procedure TFormButtonClick(Sender: TObject);
    begin
    if hWndC <> then
    begin
    SendMessage(hWndCWM_CAP_FILE_SET_CAPTURE_FILEA Longint(pchar(c:\testavi)));
    SendMessage(hWndC WM_CAP_SEQUENCE );
    end;
    end;
    procedure TFormButtonClick(Sender: TObject);
    begin
    if hWndC <> then begin
    SendMessage(hWndC WM_CAP_STOP );
    end;
    end;
    procedure TFormFormClose(Sender: TObject; var Action: TCloseAction);
    begin
    if hWndC <> then begin
    SendMessage(hWndC WM_CAP_DRIVER_DISCONNECT );
    end;
    end;
    end

    如果電腦沒有攝像頭但又想看看程序的效果可以麼?

    當然可以找個虛擬攝像頭不就搞定大家可以試試SoftCam這個軟件它是一個名副其實的軟件攝像機能模擬成為真實的攝像機提醒一下各位大家可不要用這個東東用在QQMSN等聊天軟件上欺騙MM或GG啊

    關於攝像頭編程大家也可以看看這組VCL組件DSPackDSPack是一套使用微軟Direct Show和DirectX技術的類和組件設計工作於DirectX 支持系統WinX ME 和Windows XP

    好了就介紹這些了至於視屏聊天怎麼實現就看你的了無非是把數據壓縮傳輸給對方顯示出來不過話又說回來看似簡單實現起來還有些難度的


From:http://tw.wingwit.com/Article/program/Delphi/201311/24709.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.