/// <summary> /// 开始视频捕获 /// </summary> private void StartVideoCapture() { loops: ///先将本地视频初始化为CapturerSize的高与宽 this.vCapturer = new CSS.IM.Library.AV.VideoCapturer(this.panel, 0); this.vCapturer.ConnectDevice(); if (this.vCapturer == null) { this.vCapturer = new CSS.IM.Library.AV.VideoCapturer(this.panel, 0); this.vCapturer.ConnectDevice(); goto loops; } CSS.IM.Library.AV.CaptureParms cp = this.vCapturer.CaptureParms; cp.fAbortLeftMouse = cp.fAbortRightMouse = false; cp.fYield = true; this.vCapturer.CaptureParms = cp; CSS.IM.Library.AV.BITMAPINFO h = this.vCapturer.BITMAPINFO; //如果当前摄像头不为CapturerSize,先将本地视频初始化为CapturerSize if (!(h.bmiHeader.biWidth == this.CapturerSize.Width && h.bmiHeader.biHeight == this.CapturerSize.Height)) { h.bmiHeader.biWidth = this.CapturerSize.Width; h.bmiHeader.biHeight = this.CapturerSize.Height; this.vCapturer.BITMAPINFO = h; this.vCapturer.Stop(); this.vCapturer.Close(); this.vCapturer.Disconnect(); this.vCapturer = null; goto loops; } ////本地视频初始化为VideoSizer this.vCapturer.VideoCaptured += new VideoCaptureEventHandler(vc_VideoCaptured); this.vCapturer.SetPreviewRate(25); this.vCapturer.Preview = true; this.vCapturer.CaptureWithOutFile(); this.bitmapInfo = vCapturer.BITMAPINFO; if (this.VideoCapturerBefore != null) this.VideoCapturerBefore(this, new VideoCapturedEventArgs(this.bitmapInfo));//触发视频捕获前事件 //CSS.IM.Library.Class.Calculate.WirteLog("biSize:" + bitmapInfo.bmiHeader.biSize.ToString() + " biSizeImage:" + bitmapInfo.bmiHeader.biSizeImage.ToString() // + " biBitCount:" + bitmapInfo.bmiHeader.biBitCount.ToString() + " biWidth:" + bitmapInfo.bmiHeader.biWidth.ToString() // + " biHeight:" + bitmapInfo.bmiHeader.biHeight.ToString() // + " biClrUsed:" + bitmapInfo.bmiHeader.biClrUsed.ToString() + " biClrImportant:" + bitmapInfo.bmiHeader.biClrImportant.ToString() // + " biXPelsPerMeter:" + bitmapInfo.bmiHeader.biXPelsPerMeter.ToString() + " biYPelsPerMeter:" + bitmapInfo.bmiHeader.biYPelsPerMeter.ToString() // + " biPlanes:" + bitmapInfo.bmiHeader.biPlanes.ToString() + " biCompression:" + bitmapInfo.bmiHeader.biCompression.ToString()); IniVideoRender(); }
/// <summary> /// 关闭视频捕捉 /// </summary> public void Close() { if (this.vCapturer != null) { this.vCapturer.Stop(); this.vCapturer.Close(); this.vCapturer.Disconnect(); this.vCapturer = null; this.drawDib = null; this.panel = null; this.controlVideo = null; } }