TVideoGrabber的使用(一)捕捉摄像头

使用TVideoGrabber捕捉摄像头,相当容易,只需几句代码即可解决问题,首先我们新建一个工程,然后从控件面板上拉取一个 TVideoGrabber控件到窗体中,然后再在窗体上放置四个Button,分别将Caption设为播放,暂停,停止,关闭,name分别设为 BtnPlay,BtnPause,BtnStop,BtnClose将TVideoGrabber1的VideoSource的属性设置为 vs_VideoCaptureDevice

为各个按钮添加点击事件,完整代码如下:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, VidGrab;

type
  TForm1 = class(TForm)
    VideoGrabber1: TVideoGrabber;
    BtnPlay: TButton;
    BtnPause: TButton;
    BtnStop: TButton;
    BtnClose: TButton;
    procedure BtnPlayClick(Sender: TObject);
    procedure BtnPauseClick(Sender: TObject);
    procedure BtnStopClick(Sender: TObject);
    procedure BtnCloseClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

//开启视屏

procedure TForm1.BtnPlayClick(Sender: TObject);
begin
  videoGrabber1.StartPreview;
end;

//暂停或继续

procedure TForm1.BtnPauseClick(Sender: TObject);
begin
 if BtnPause.Caption = '暂停' then
    begin
      btnPause.Caption := '继续';
      VideoGrabber1.PausePreview;
    end
 else
    begin
      btnPause.Caption := '暂停';
      VideoGrabber1.ResumePreview;
    end;
end;

//停止视屏

procedure TForm1.BtnStopClick(Sender: TObject);
begin
  videoGrabber1.StopPreview;
end;

//关闭窗体

procedure TForm1.BtnCloseClick(Sender: TObject);
begin
  close;
end;

end.

以上代码在Delphi7+windows XP Sp3中测试通过

原文转发自:http://www.cnblogs.com/zhusd/archive/2010/06/22/1762531.html

这里有个下载地址:下载

上一篇:主流经济学简史——从古典政治经济学到现代经济学


下一篇:Xcode - 必不可少的插件