如何 Capture MediaPlay 正在播放的影像? |
|
tenbao
一般會員 發表:8 回覆:4 積分:2 註冊:2002-05-29 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
轉貼的, 參考看看:
How can I capture an image from a video source? 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 11; 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.發表人 - hagar 於 2002/06/21 09:31:50 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |