中国程序员联盟 正在重新改版中ing 不便之处还请见谅 改版后将内容涉及java delphi .net php
 
  首页 | 数据库开发 | 网络通讯 | 多线程 | 多媒体开发 | 图像处理 | 程序人生 | 系统函数 | 控件开发 | Web服务
 
  当前位置:笨鱼delphi技术网>图像处理>文章内容

delphi How can I capture an image from a video source

来源:国外 关于:轶名 发布时间:2007-06-29   [收藏] [推荐]
For a complete example, you need to get the Microsoft Video for Windows SDK. The following simple example shows how to open the default video capture device, grab a frame from the device, save a frame from the device to the disk as a .BMP (device independent bitmap) file, record a .AVI file (with sound, but without preview), and close the device. Note: You must have a video capture device installed for this example to work.
Example:
unit Unit ;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
   Dialogs, ExtCtrls, StdCtrls;
type
  TForm  = class(TForm)
    Panel : TPanel;
    OpenVideo: TButton;
    CloseVideo: TButton;
    GrabFrame: TButton;
    SaveBMP: TButton;
    StartAVI: TButton;
    StopAVI: TButton;
    SaveDialog : TSaveDialog;
    procedure FormCreate(Sender: TObject);
    procedure OpenVideoClick(Sender: TObject);
    procedure CloseVideoClick(Sender: TObject);
    procedure GrabFrameClick(Sender: TObject);
    procedure SaveBMPClick(Sender: TObject);
    procedure StartAVIClick(Sender: TObject);
    procedure StopAVIClick(Sender: TObject);
  private
    { Private declarations }
    hWndC : THandle;
    CapturingAVI : bool;
  public
    { Public declarations }
  end;
var
  Form : TForm ;
implementation
{$R *.DFM}
const WM_CAP_START                  = WM_USER;
const WM_CAP_STOP                   = WM_CAP_START + 68;
const WM_CAP_DRIVER_CONNECT         = WM_CAP_START +  0;
const WM_CAP_DRIVER_DISCONNECT      = WM_CAP_START +   ;
const WM_CAP_SAVEDIB                = WM_CAP_START + 25;
const WM_CAP_GRAB_FRAME             = WM_CAP_START + 60;
const WM_CAP_SEQUENCE               = WM_CAP_START + 62;
const WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START +  20;
function capCreateCaptureWindowA(lpszWindowName : PCHAR;
                                 dwStyle : longint;
                                 x : integer;
                                 y : integer;
                                 nWidth : integer;
                                 nHeight : integer;
                                 ParentWin  : HWND;
                                 nId : integer): HWND;
                                 STDCALL EXTERNAL 'AVICAP32.DLL';
procedure TForm .FormCreate(Sender: TObject);
begin
  CapturingAVI := false;
  hWndC := 0;
  SaveDialog .Options :=
    [ofHideReadOnly, ofNoChangeDir, ofPathMustExist]
end;
procedure TForm .OpenVideoClick(Sender: TObject);
begin
  hWndC := capCreateCaptureWindowA('My Own Capture Window',
                                   WS_CHILD or WS_VISIBLE ,
                                   Panel .Left,
                                   Panel .Top,
                                   Panel .Width,
                                   Panel .Height,
                                   Form .Handle,
                                   0);
  if hWndC <> 0 then
    SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
end;
procedure TForm .CloseVideoClick(Sender: TObject);
begin
  if hWndC <> 0 then begin
    SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
   hWndC := 0;
   end;
end;
procedure TForm .GrabFrameClick(Sender: TObject);
begin
  if hWndC <> 0 then
    SendMessage(hWndC, WM_CAP_GRAB_FRAME, 0, 0);
end;
procedure TForm .SaveBMPClick(Sender: TObject);
begin
  if hWndC <> 0 then begin
    SaveDialog .DefaultExt := 'bmp';
    SaveDialog .Filter := 'Bitmap files (*.bmp)|*.bmp';
    if SaveDialog .Execute then
      SendMessage(hWndC,
                  WM_CAP_SAVEDIB,
                  0,
                  longint(pchar(SaveDialog .FileName)));
  end;
end;
procedure TForm .StartAVIClick(Sender: TObject);
begin
  if hWndC <> 0 then begin
    SaveDialog .DefaultExt := 'avi';
    SaveDialog .Filter := 'AVI files (*.avi)|*.avi';
    if SaveDialog .Execute then begin
       CapturingAVI := true;
       SendMessage(hWndC,
                   WM_CAP_FILE_SET_CAPTURE_FILEA,
                   0,
                   Longint(pchar(SaveDialog .FileName)));
       SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0);
    end;
  end;
end;
procedure TForm .StopAVIClick(Sender: TObject);
begin
  if hWndC <> 0 then begin
    SendMessage(hWndC, WM_CAP_STOP, 0, 0);
    CapturingAVI := false;
  end;
end;
end.

[浏览: 次]   
上一篇:delphi DSPACK视频开发   下一篇:delphi 如何屏蔽控件的默认右键菜单
[收藏] [推荐] [返回顶部] [打印本页] [关闭窗口]  
    评论加载中…
google adsense热点文章
·delphi DSPACK视频开发
·delphi Delphi Video for Windows 视频
·delphi 视频软件开发
·delphi 用Delphi开发视频捕获程序
·delphi 保存或加载图片成流TStream
·delphi MS的AVICAP32.DLL的API
·delphi 如何屏蔽控件的默认右键菜单
·delphi 压缩图像资料
·delphi 如何将位图、图片、图元件到剪
     delphi技术网 | firefox 下载 | Avant Browser下载 | dedecms 技术网 | drupal 爱好者 | php 技术网
  Copyright@www.delphichm.com,2006-2009.All Rights Reserved.
 
程序员联盟 | delphi Java .net|QQ:707102932