全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2210
推到 Plurk!
推到 Facebook!

如何 Capture MediaPlay 正在播放的影像?

 
tenbao
一般會員


發表:8
回覆:4
積分:2
註冊:2002-05-29

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-06-21 08:59:27 IP:218.5.xxx.xxx 未訂閱
哪一位仁兄可以幫忙一下,我的程式裡已經加入了 MediaPlay 的元件,但是!目前因為需要 Capture 裡面的影像變為 BMP 或是 JPEG 等 圖片,不知道要如何下手,請大家幫忙一下!
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-06-21 09:15:26 IP:211.22.xxx.xxx 未訂閱
轉貼的, 參考看看: 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
系統時間:2024-12-04 1:10:49
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!