/// <summary> /// 开启摄像头 /// </summary> public void StartWebCam() { var lpszName = new byte[100]; var lpszVer = new byte[100]; AviCapture.capGetDriverDescriptionA(1, lpszName, 100, lpszVer, 100); this._lwndC = AviCapture.capCreateCaptureWindowA(lpszName, AviCapture.WsVisible + AviCapture.WsChild, 0, 0, _mWidth, _mHeight, _mControlPtr, 0); if (this.CapDriverConnect(this._lwndC, 0)) { this.CapPreviewRate(this._lwndC, 66); this.CapPreview(this._lwndC, true); this.CapOverlay(this._lwndC, true); var bitmapinfo = new AviCapture.Bitmapinfo(); bitmapinfo.bmiHeader.biSize = AviCapture.SizeOf(bitmapinfo.bmiHeader); bitmapinfo.bmiHeader.biWidth = this._mWidth; bitmapinfo.bmiHeader.biHeight = this._mHeight; bitmapinfo.bmiHeader.biPlanes = 1; bitmapinfo.bmiHeader.biBitCount = 24; this.CapSetVideoFormat(this._lwndC, ref bitmapinfo, AviCapture.SizeOf(bitmapinfo)); this._mFrameEventHandler = new AviCapture.FrameEventHandler(FrameCallBack); this.CapSetCallbackOnFrame(this._lwndC, this._mFrameEventHandler); AviCapture.SetWindowPos(this._lwndC, 0, 0, 0, _mWidth, _mHeight, 6); } }
private bool CapSetVideoFormat(IntPtr hCapWnd, ref AviCapture.Bitmapinfo bmpFormat, int capFormatSize) { return(AviCapture.SendMessage(hCapWnd, AviCapture.WmCapSetVideoformat, capFormatSize, ref bmpFormat)); }