用Delphi编写视频捕捉程序:
首先,在窗体中放入TMediaPlayer,TMainMenu,TOpendialog,TPaintBox,TButton组件,并调整好位置。
唉,懒得详细介绍了,自己看代码吧!(其中视频播放位置在rect(200,0,400,200),视频捕捉位置在rect(0,0,200,200))
整个程序的源代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, MPlayer, Menus;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
file1: TMenuItem;
open1: TMenuItem;
exit1: TMenuItem;
OpenDialog1: TOpenDialog;
MediaPlayer1: TMediaPlayer;
PaintBox1: TPaintBox;
Button1: TButton;
procedure open1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure PaintBox1Click(Sender: TObject);
private
imgbitmap: Tbitmap;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.open1Click(Sender: TObject);
begin
if opendialog1.Execute then
begin
mediaplayer1.FileName:=opendialog1.FileName;
mediaplayer1.Open;
mediaplayer1.Display:=form1;
mediaplayer1.DisplayRect:=rect(200,0,400,200);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
imgbitmap.Canvas.CopyRect(rect(0,0,200,200),form1.canvas,rect(200,0,400,200));
paintbox1.Invalidate;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
imgbitmap:=tbitmap.Create;
imgbitmap.Height:=200;
imgbitmap.Width:=200;
imgbitmap.Canvas.Rectangle(0,0,200,200);
imgbitmap.SaveToFile('img.bmp');
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
canvas.FrameRect(rect(0,0,200,200));
end;
procedure TForm1.PaintBox1Click(Sender: TObject);
begin
paintbox1.Canvas.CopyRect(rect(0,0,200,200),imgbitmap.Canvas,rect(0,0,200,200));
end;
end.