usingSystem;usingSystem.Runtime.InteropServices; Public classVideoapi//Video API Classes{ //Video API calls[DllImport ("Avicap32.dll")] Public Static externIntPtr Capcreatecapturewindowa (byte[] lpszWindowName,intDwstyle,intXintYintNwidth,intNheight, IntPtr hwndparent,intNID); [DllImport ("Avicap32.dll")] Public Static extern BOOLCapgetdriverdescriptiona ( ShortWdriver,byte[] LpszName,intCBName,byte[] Lpszver,intcbver); [DllImport ("User32.dll")] Public Static extern BOOLSendMessage (IntPtr hWnd,intWmsg,BOOLWParam,intLParam); [DllImport ("User32.dll")] Public Static extern BOOLSendMessage (IntPtr hWnd,intWmsg, ShortWParam,intLParam); //Constants Public Const intWm_user =0x400; Public Const intWs_child =0x40000000; Public Const intWs_visible =0x10000000; Public Const intSwp_nomove =0x2; Public Const intSwp_nozorder =0x4; Public Const intWm_cap_driver_connect = Wm_user +Ten; Public Const intWm_cap_driver_disconnect = Wm_user + One; Public Const intWm_cap_set_callback_frame = Wm_user +5; Public Const intWm_cap_set_preview = Wm_user + -; Public Const intWm_cap_set_previewrate = Wm_user + the; Public Const intWm_cap_set_videoformat = Wm_user + $; Public Const intWm_cap_start =Wm_user; Public Const intWm_cap_savedib = Wm_cap_start + -;} Public classCvideo//Video Class{ PrivateIntPtr LWNDC;//To save an unsigned handle PrivateIntPtr mcontrolptr;//Save Management Indicators Private intMwidth; Private intMheight; PublicCvideo (INTPTR handle,intWidthintheight) {Mcontrolptr= handle;//to display a handle to a video controlMwidth = width;//Video WidthMheight = height;//Video Height } /// <summary> ///turn on the video device/// </summary> Public voidStartwebcam () {byte[] LpszName =New byte[ -]; byte[] Lpszver =New byte[ -]; Videoapi.capgetdriverdescriptiona (0, LpszName, -, Lpszver, -); This. LWNDC = Videoapi.capcreatecapturewindowa (lpszName, Videoapi.ws_child | Videoapi.ws_visible,0,0, Mwidth, Mheight, Mcontrolptr,0); if(Videoapi.sendmessage (LWNDC, Videoapi.wm_cap_driver_connect,0,0) {videoapi.sendmessage (LWNDC, Videoapi.wm_cap_set_previewrate, -,0); Videoapi.sendmessage (LWNDC, Videoapi.wm_cap_set_preview,true,0); } } /// <summary> ///Turn off the video device/// </summary> Public voidClosewebcam () {videoapi.sendmessage (LWNDC, Videoapi.wm_cap_driver_disconnect,0,0); } /// <summary> ///Take Pictures/// </summary> /// <param name= "path" >the path to save the BMP file</param> Public voidGrabimage (IntPtr Hwndc,stringpath) {INTPTR hbmp=marshal.stringtohglobalansi (path); Videoapi.sendmessage (LWNDC, Videoapi.wm_cap_savedib,0, Hbmp.toint32 ()); }}
C # Videoapi