用api调用摄像头

//定义变量
uint lhand

//定义常数
long WM_USER=1024
long WM_CAP_START = WM_USER
long WM_CAP_STOP = WM_CAP_START + 68
long WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
long WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
long WM_CAP_SAVEDIB = WM_CAP_START + 25
long WM_CAP_GRAB_FRAME = WM_CAP_START + 60
long WM_CAP_SEQUENCE = WM_CAP_START + 62
long WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20
long WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+  63
long WM_CAP_SET_OVERLAY =WM_CAP_START+  51
long WM_CAP_SET_PREVIEW =WM_CAP_START+  50
long WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6
long WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2
long WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3
long WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5
long WM_CAP_SET_SCALE=WM_CAP_START+  53
long WM_CAP_SET_PREVIEWRATE=WM_CAP_START+  52

 

//定义api
function ulong capCreateCaptureWindowA(string lpszWindowName,ulong dwStyle,long x ,long y ,long nWidth ,long nHeight ,ulong ParentWin ,long  nId ) LIBRARY 'AVICAP32.DLL'  

//初始化代码
string lpszName
ulong l1
l1=handle(w_main)

 

lpszName='摄像头界面...'
lhand=capCreateCaptureWindowA(lpszName,262144+12582912+1073741824 + 268435456 ,0,0,200,200,l1,0)
if lhand <> 0 then  
  send(lhand, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0)
  send(lhand, WM_CAP_SET_CALLBACK_ERROR, 0, 0)
  send(lhand, WM_CAP_SET_CALLBACK_STATUSA, 0, 0)
  send(lhand, WM_CAP_DRIVER_CONNECT, 0, 0)
  send(lhand, WM_CAP_SET_SCALE, 1, 0)
  send(lhand, WM_CAP_SET_PREVIEWRATE, 66, 0)
  send(lhand, WM_CAP_SET_OVERLAY, 1, 0)
  send(lhand, WM_CAP_SET_PREVIEW, 1, 0)
end if

 

//保存到文件
string s
s='c:/save.avi'
if lhand<>0 then
Send(lhand,WM_CAP_FILE_SET_CAPTURE_FILEA,0, s);
Send(lhand,WM_CAP_SEQUENCE, 0, 0)  //开始捕捉
end if

 

//停止保存
  send(lhand, WM_CAP_STOP, 0, 0)

 

//保存为图片
string s
s='c:/save.bmp'
if lhand <> 0 then
Send(lhand,WM_CAP_SAVEDIB,0,s);
end if

 

//没有摄像头的可以去下载一个如下的软件,可以虚拟摄像头(此软件可以放一个电影,代替正常摄像头的摄像内容)
Vandate Virtual Camera 虚拟摄像头 1.5.1.exe

 

你可能感兴趣的:(Library,&,API,C,&,C++)