public void StartWebCam() //打开视频设备 { byte[] lpszName = new byte[100]; byte[] lpszVer = new byte[100]; VideoAPI.capGetDriverDescriptionA(0, lpszName, 100, lpszVer, 100); 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, 100, 0); VideoAPI.SendMessage(lwndC, VideoAPI.WM_CAP_SET_PREVIEW, true, 0); } }
public void GrabImage(IntPtr hWndC, string path) //拍照 { IntPtr hBmp = Marshal.StringToHGlobalAnsi(path); VideoAPI.SendMessage(lwndC, VideoAPI.WM_CAP_SAVEDIB, 0, hBmp.ToInt32()); }
public void CloseWebcam()//关闭视频设备 { VideoAPI.SendMessage(lwndC, VideoAPI.WM_CAP_DRIVER_DISCONNECT, 0, 0); }
/// <summary> /// 拍照 /// </summary> /// <param name="path">要保存bmp文件的路径</param> public void GrabImage(string path) { IntPtr hBmp = Marshal.StringToHGlobalAnsi(path); //将托管字符串复制到非托管内存中,并返回内存地址 VideoAPI.SendMessage(lwndC, VideoAPI.WM_CAP_FILE_SAVEDIB, 0, hBmp.ToInt32()); //将拍照图片以位图文件的方式存到硬盘指定路径 }