/// <summary> /// 开始监控 /// </summary> private void startMonitor() { if (VideoOperate.VCAInitSdk(this.Handle, VideoOperate.DISPLAYTRANSTYPE.PCI_MEMORY_VIDEOMEMORY, false)) { m_dwDevNum = VideoOperate.VCAGetDevNum(); if (m_dwDevNum == 0) { MessageBox.Show("VC404卡驱动程序没有安装"); } else { for (int i = 0; i < m_dwDevNum; i++) { foreach (Control ctl in this.Controls) { if ((ctl is Panel) && (ctl.Name == "plVideo" + (i + 1))) { VideoOperate.VCAOpenDevice(i, ctl.Handle); VideoOperate.VCAStartVideoPreview(i); } } } } } }
//录像 private void btnVideo_Click(object sender, EventArgs e) { if (btnVideo.Text == "录像") { sfDialog.Filter = "*.avi|*.avi"; sfDialog.Title = "保存视频文件"; sfDialog.InitialDirectory = Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\")) + "\\Video\\"; if (sfDialog.ShowDialog() == DialogResult.OK) { btnVideo.Text = "停止录像"; VideoOperate.VCASetKeyFrmInterval(0, 250); //设置MPEG压缩的关键帧间隔 VideoOperate.VCASetBitRate(0, 256); //设置MPEG压缩的位率 VideoOperate.VCASetVidCapFrameRate(0, 25, false); //设置视频捕获频率 VideoOperate.VCASetVidCapSize(0, 320, 240); //设置视频捕获尺寸,此处即为宽320高240 VideoOperate.VCASetXVIDQuality(0, 10, 3); //设置MPEG4_XVID压缩的质量 VideoOperate.VCASetXVIDCompressMode(0, VideoOperate.COMPRESSMODE.XVID_VBR_MODE); //设置MPEG4_XVID压缩的模式 VideoOperate.VCAStartVideoCapture(0, VideoOperate.CAPMODEL.CAP_MPEG4_STREAM, VideoOperate.MP4MODEL.MPEG4_AVIFILE_CALLBACK, sfDialog.FileName); //开始视频捕获 } } else if (btnVideo.Text == "停止录像") { btnVideo.Text = "录像"; VideoOperate.VCAStopVideoCapture(0); //停止视频捕获 } }
//移动窗体位置时,视频随之移动 private void frmMain_Move(object sender, EventArgs e) { for (int i = 0; i < m_dwDevNum; i++) { plVideo1.Invalidate(); VideoOperate.VCAUpdateOverlayWnd(this.Handle); VideoOperate.VCAUpdateVideoPreview(i, plVideo1.Handle); } }
//快照 private void btnSnapShots_Click(object sender, EventArgs e) { if (rbtnBMP.Checked) { VideoOperate.VCASaveAsBmpFile(intFlag, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\")) + "\\Photo\\" + DateTime.Now.ToFileTime() + ".bmp"); } else { VideoOperate.VCASaveAsJpegFile(intFlag, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\")) + "\\Photo\\" + DateTime.Now.ToFileTime() + ".jpg", 100); } }
/// <summary> /// 自动录像 /// </summary> private void AutoVideo() { btnVideo.Text = "停止录像"; string strPath = Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).Substring(0, Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\")) + "\\Video\\"; VideoOperate.VCASetKeyFrmInterval(intFlag, 250); VideoOperate.VCASetBitRate(intFlag, 256); VideoOperate.VCASetVidCapFrameRate(intFlag, 25, false); VideoOperate.VCASetVidCapSize(intFlag, 320, 240); VideoOperate.VCASetXVIDQuality(intFlag, 10, 3); VideoOperate.VCASetXVIDCompressMode(intFlag, VideoOperate.COMPRESSMODE.XVID_VBR_MODE); VideoOperate.VCAStartVideoCapture(intFlag, VideoOperate.CAPMODEL.CAP_MPEG4_STREAM, VideoOperate.MP4MODEL.MPEG4_AVIFILE_CALLBACK, strPath + DateTime.Now.ToString("yyyyMMddhhmmss") + ".avi"); }
/// <summary> /// 移动窗体位置时,视频随之移动 /// </summary> private void MoveVideo() { for (int i = 0; i < m_dwDevNum; i++) { foreach (Control ctl in this.Controls) { if ((ctl is Panel) && (ctl.Name == "plVideo" + (i + 1))) { ctl.Invalidate(); VideoOperate.VCAUpdateOverlayWnd(this.Handle); VideoOperate.VCAUpdateVideoPreview(i, ctl.Handle); } } } }
//停止监控 private void btnStop_Click(object sender, EventArgs e) { if (btnStop.Text == "停止") { string strDPath = Application.StartupPath; string strPath = strDPath.Substring(0, strDPath.LastIndexOf("\\")).Substring(0, strDPath.Substring(0, strDPath.LastIndexOf("\\")).LastIndexOf("\\")) + "\\Image\\主页面\\bg.bmp"; setVideoBG(strPath); VideoOperate.VCAUnInitSdk(); btnStop.Text = "开始"; } else if (btnStop.Text == "开始") { setVideoBG(""); startMonitor(); btnStop.Text = "停止"; } }
//开始监控 protected void startMonitor() { if (VideoOperate.VCAInitSdk(this.Handle, VideoOperate.DISPLAYTRANSTYPE.PCI_MEMORY_VIDEOMEMORY, false)) { m_dwDevNum = VideoOperate.VCAGetDevNum(); if (m_dwDevNum == 0) { MessageBox.Show("VC404卡驱动程序没有安装"); } else { for (int i = 0; i < m_dwDevNum; i++) { VideoOperate.VCAOpenDevice(i, plVideo1.Handle); VideoOperate.VCAStartVideoPreview(i); } } } }
//停止监控 private void btnStop_Click(object sender, EventArgs e) { try { if (btnStop.Text == "停止") { string strDPath = Application.StartupPath; string strPath = strDPath.Substring(0, strDPath.LastIndexOf("\\")).Substring(0, strDPath.Substring(0, strDPath.LastIndexOf("\\")).LastIndexOf("\\")) + "\\Image\\主页面\\主界面图片.bmp"; plVideo1.BackgroundImage = System.Drawing.Image.FromFile(strPath); VideoOperate.VCAUnInitSdk(); btnStop.Text = "开始"; } else if (btnStop.Text == "开始") { plVideo1.BackgroundImage = null; startMonitor(); btnStop.Text = "停止"; } } catch (Exception ex) { MessageBox.Show("非法错误。" + ex.ToString()); } }
//控制视频窗口的色度 private void TBarColor_Scroll(object sender, EventArgs e) { VideoOperate.VCASetVidDeviceColor(intFlag, VideoOperate.COLORCONTROL.HUE, TBarColor.Value); }
//控制视频窗口的饱和度 private void TBarSaturation_Scroll(object sender, EventArgs e) { VideoOperate.VCASetVidDeviceColor(intFlag, VideoOperate.COLORCONTROL.SATURATION, TBarSaturation.Value); }
//控制视频窗口的亮度 private void TBarBright_Scroll(object sender, EventArgs e) { VideoOperate.VCASetVidDeviceColor(intFlag, VideoOperate.COLORCONTROL.BRIGHTNESS, TBarBright.Value); }