可以使用vfw,在delphi的帮助中有关于ms的sdk help files,Microsoft Multimedia Programmer's Reference
在网上找一个vfw.pas,包含在工程中即可使用里面介绍的函数。
下面是我参考别人的代码写的一些程序,用于图形的获取
uses FSVS, VFW, FBaseInfo;
var
DriverID:integer;
//可以得到视频数据指针的结构变量,用于回调函数中
//VideoStr: LPVIDEOHDR;
//用于设置设备属性的结构变量
CapParms: TCaptureParms;
procedure TGetImage.SetButton(Status:boolean);
begin
bnSelectDriver.Enabled:=not Status;
bnOpenVideo.Enabled:=not Status;
bnCapturePict.Enabled:=Status;
bnOK.Enabled:=Status;
bnCloseVideo.Enabled:=Status;
bnGrabFrameNoStop.Enabled:=Status;
bnDlgVideoSource.Enabled:=Status;
bnDlgVideoFormat.Enabled:=Status;
bnDlgVideoDisplay.Enabled:=Status;
bnDlgVideoCompression.Enabled:=Status;
end;
procedure TGetImage.bnSelectDriverClick(Sender: TObject);
begin
DriverID:=SVS.execute;
if DriverID=-1 then
begin
DriverID:=0;
ShowMessage('本机没有安装摄像头或没有选择正确的驱动!');
end;
end;
procedure TGetImage.bnOpenVideoClick(Sender: TObject);
begin
hWnDc:=capCreateCaptureWindowA(PChar('获取照片窗口'),WS_CHILD or WS_VISIBLE,
0,0,Pict.Width,Pict.Height,Pict.Handle,DriverID);
//定义一个帧捕获回调函数
//CapSetCallbackOnFrame (hWndc,(@FrameCallBack));
//将一个捕获窗口与一个设备驱程相关联,第二个参数是个序号,当系统中装有多个显视驱动程序时,其值分别依次为0到总个数
CapDriverConnect(hWndc, 0);
//设置设备属性的结构变量
CapParms.dwRequestMicroSecPerFrame:=40000;
CapParms.fLimitEnabled := FALSE;
CapParms.fCaptureAudio := FALSE; // NO Audio
CapParms.fMCIControl := FALSE;
CapParms.fYield := TRUE;
CapParms.vKeyAbort := VK_ESCAPE;
CapParms.fAbortLeftMouse := FALSE;
CapParms.fAbortRightMouse := FALSE;
//使设置生效
CapCaptureSetSetup(hWndc,(@CapParms),sizeof(TCAPTUREPARMS));
//设置预览时的比例
CapPreviewScale(hWndc, false);
//设置预览时的帧频率
CapPreviewRate(hWndc,66);
//如果要捕获视频流,则要使用函数指定不生成文件。否则将会自动生成AVI文件
CapCaptureSequenceNoFile(hWndc);
//指定是否使用叠加模式,使用为1,否则为0
CapOverlay(hWndc, false);
//打开预览
CapPreview(hWndc, true);
SetButton((Hwndc>0));
end;
procedure TGetImage.bnCloseVideoClick(Sender: TObject);
begin
//停止捕获
capCaptureAbort(hWndc);
//将捕获窗同驱动器断开
capDriverDisconnect(hWndc);
SetButton(false);
end;
procedure TGetImage.bnCapturePictClick(Sender: TObject);
begin
capGrabFrame(hWndc);
end;
procedure TGetImage.FormCreate(Sender: TObject);
begin
hWnDc:=0;
DriverID:=0;
end;
procedure TGetImage.bnDlgVideoSourceClick(Sender: TObject);
begin
capDlgVideoSource(hWndc);
end;
procedure TGetImage.bnDlgVideoFormatClick(Sender: TObject);
begin
capDlgVideoFormat(Hwndc);
end;
procedure TGetImage.bnDlgVideoDisplayClick(Sender: TObject);
begin
capDlgVideoDisplay(hWndc);
end;
procedure TGetImage.bnDlgVideoCompressionClick(Sender: TObject);
begin
capDlgVideoCompression(hWndc);
end;
procedure TGetImage.bnGrabFrameNoStopClick(Sender: TObject);
begin
capGrabFrameNoStop(hWndc);
end;
procedure TGetImage.bnOKClick(Sender: TObject);
begin
if capEditCopy(hWndc) then
begin
BaseInfo.Photo.PasteFromClipboard;
BaseInfo.Photo.Picture.Bitmap.Width:=150;
BaseInfo.Photo.Picture.Bitmap.Height:=200;
end
else
ShowMessage('没有抓取图像!');
end;
procedure TGetImage.FormActivate(Sender: TObject);
begin
if hWndc>0 then capPreview(hWndc,cbPreview.Checked);//如果预览,设置
end;
procedure TGetImage.cbPreviewClick(Sender: TObject);
begin
if hWndc>0 then capPreview(hWndc,cbPreview.Checked);
end;
procedure TGetImage.cbOverlayClick(Sender: TObject);
begin
if hWndc>0 then capOverlay(hWndc,cbOverlay.Checked);
end;
procedure TGetImage.cbOtherSetClick(Sender: TObject);
begin
bnGrabFrameNoStop.Visible:=cbOtherSet.Checked;
bnDlgVideoSource.Visible:=cbOtherSet.Checked;
bnDlgVideoFormat.Visible:=cbOtherSet.Checked;
bnDlgVideoDisplay.Visible:=cbOtherSet.Checked;