/// <summary> /// 打开摄像头 /// </summary> public void StartWebCam() { byte[] lpszName = new byte[100]; byte[] lpszVer = new byte[100]; ShowVideo.capGetDriverDescriptionA(0, lpszName, 100, lpszVer, 100); this.lwndC = ShowVideo.capCreateCaptureWindowA(lpszName, ShowVideo.WS_VISIBLE + ShowVideo.WS_CHILD, 0, 0, mWidth, mHeight, mControlPtr, 0); if (this.capDriverConnect(this.lwndC, 0)) { this.capPreviewRate(this.lwndC, 66); this.capPreview(this.lwndC, true); ShowVideo.BITMAPINFO bitmapinfo = new ShowVideo.BITMAPINFO(); bitmapinfo.bmiHeader.biSize = ShowVideo.SizeOf(bitmapinfo.bmiHeader); bitmapinfo.bmiHeader.biWidth = 352; bitmapinfo.bmiHeader.biHeight = 288; bitmapinfo.bmiHeader.biPlanes = 1; bitmapinfo.bmiHeader.biBitCount = 24; this.capSetVideoFormat(this.lwndC, ref bitmapinfo, ShowVideo.SizeOf(bitmapinfo)); this.mFrameEventHandler = new ShowVideo.FrameEventHandler(FrameCallBack); this.capSetCallbackOnFrame(this.lwndC, this.mFrameEventHandler); ShowVideo.SetWindowPos(this.lwndC, 0, 0, 0, mWidth, mHeight, 6); } }
private bool capSetVideoFormat(IntPtr hCapWnd, ref ShowVideo.BITMAPINFO BmpFormat, int CapFormatSize) { return(ShowVideo.SendMessage(hCapWnd, ShowVideo.WM_CAP_SET_VIDEOFORMAT, CapFormatSize, ref BmpFormat)); }