我有一个简单的程序发给你吧!
unit Ubutu;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, RzPanel, StdCtrls, Buttons, UhGlobal_Var, UhBase_Function,
MPlayer, DirectShow9,DSPack,DSUtil;
type
TF_butu = class(TForm)
RzPanel1: TRzPanel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
RzPanel2: TRzPanel;
VideoWindow: TVideoWindow;
Filter: TFilter;
SampleGrabber: TSampleGrabber;
FilterGraph: TFilterGraph;
SaveDialog1: TSaveDialog;
procedure jianwenja(wenja: string);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
imapath: string;
SysDev: TSysDevEnum;
end;
var
F_butu: TF_butu;
implementation
uses Utujianadd;
{$R *.dfm}
{ TF_butu }
procedure TF_butu.jianwenja(wenja: string);
begin
try
SysDev:= TSysDevEnum.Create(CLSID_VideoInputDeviceCategory);
if SysDev.CountFilters > 0 then
begin
FilterGraph.ClearGraph;
FilterGraph.Active := false;
Filter.BaseFilter.Moniker := SysDev.GetMoniker(0);
FilterGraph.Active := true;
with FilterGraph as ICaptureGraphBuilder2 do
RenderStream(@PIN_CATEGORY_PREVIEW, nil, Filter as IBaseFilter, SampleGrabber as IBaseFilter, VideoWindow as IbaseFilter);
FilterGraph.Play;
end;
imapath := ExtractFilePath(Application.ExeName) + 'image/';
if not DirectoryExists(imapath) then
mkdir(imapath);
imapath := imapath + idno + '/';
if not DirectoryExists(imapath) then
mkdir(imapath);
except
on E: exception do
begin
UhBase_Function.Write_log('<<TF_butu<<jianwenja<< 建立图片文件夹' + E.Message);
exit;
end;
end;
end;
procedure TF_butu.BitBtn2Click(Sender: TObject);
var
MyBmp: Tbitmap;
MyCanvas: TCanvas;
DC: HDC;
Rect: TRect;
begin
MyBmp := Tbitmap.Create;
MyCanvas := TCanvas.Create;
Rect := VideoWindow.ClientRect;
DC := GetDC(VideoWindow.Handle);
MyCanvas.Handle := DC;
MyBmp.Width := Rect.Right + 5 + Rect.Left - 10;
MyBmp.height := Rect.Bottom + 5 + Rect.Top - 10;
MyBmp.Canvas.CopyRect(Rect, MyCanvas, Rect);
imapat := imapath + F_tujianadd.RzComboBox1.Text + formatDateTime('yymmdd', now) + '.bmp';
MyBmp.SaveToFile(imapat);
ReleaseDC(0, DC);
MyBmp.Free;
MyCanvas.Free;
//MediaPlayer1.Play;
SampleGrabber.GetBitmap(F_tujianadd.Image1.Picture.Bitmap);//F_tujianadd.Image1.Picture.Bitmap.LoadFromFile(imapat);
F_tujianadd.tutpye := '1';
Close;
end;
procedure TF_butu.BitBtn3Click(Sender: TObject);
begin
Close;
end;
procedure TF_butu.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SysDev.Free;
FilterGraph.ClearGraph;
FilterGraph.Active := false;
Action := cafree;
end;
end.
你自已看看吧