实例介绍
【实例截图】
【核心代码】
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace yundemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); context = SynchronizationContext.Current; // 线程间信息同步 } #region 视频 SynchronizationContext context = SynchronizationContext.Current; // 线程间信息同步 bool isStartVideo1 = false; /// <summary> /// 登录ID /// </summary> private int pLoginID1 = -1; /// <summary> /// 硬件信息 /// </summary> // private CHCNetSDK.NET_DVR_DEVICEINFO_V30 deviceInfo; //获取视频路数 private int BindVideo1 = 0; private int[] pRealPlayHandle; public void InitVideo() { try { ThreadStart tsVideo = new ThreadStart(delegate () { context.Post((o) => { pRealPlayHandle = new int[4]; BindVideo1 = 0; #region 摄像头1 isStartVideo1 = CHCNetSDK.NET_DVR_Init(); //设置连接时间与重连时间 //设备用户信息获得 CHCNetSDK.NET_DVR_DEVICEINFO_V30 deviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30(); pLoginID1 = CHCNetSDK.NET_DVR_Login_V30(IP, Port, Admin, Password, ref deviceInfo); if (pLoginID1 != -1) { // byte CountNum = this.deviceInfo.byChanNum >= deviceInfo.byIPChanNum ? deviceInfo.byChanNum : deviceInfo.byIPChanNum; CHCNetSDK.NET_DVR_PREVIEWINFO lpClientInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO(); lpClientInfo.lChannel = 1; BindVideo1 = 1; lpClientInfo.dwStreamType = 1;//码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推 lpClientInfo.dwLinkMode = 1;//连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP lpClientInfo.bBlocked = false; //0- 非阻塞取流,1- 阻塞取流 lpClientInfo.hPlayWnd = this.pictureBox1.Handle; IntPtr pUser = new IntPtr(); this.pRealPlayHandle[0] = CHCNetSDK.NET_DVR_RealPlay_V40(pLoginID1, ref lpClientInfo, null, pUser); pictureBox1.Refresh(); } #endregion }, string.Empty); }); Thread th = new Thread(tsVideo); th.IsBackground = true; th.Start(); } catch { MessageBox.Show("连接异常,建议重启"); Application.Exit(); } } private void VideoClose() { CHCNetSDK.NET_DVR_Cleanup(); } private void Form1_Load(object sender, EventArgs e) { InitConfig(); InitVideo(); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { try { VideoClose(); } catch { Application.Exit(); } } #endregion #region 云台 private void button5_Click_1(object sender, EventArgs e) { YunControl(CHCNetSDK.TILT_UP);//上 } private void button8_Click_1(object sender, EventArgs e) { YunControl(CHCNetSDK.TILT_DOWN);//下 } private void button2_Click_1(object sender, EventArgs e) { YunControl(CHCNetSDK.PAN_LEFT); } private void button4_Click_1(object sender, EventArgs e) { YunControl(CHCNetSDK.PAN_RIGHT);//右 } private void button1_Click(object sender, EventArgs e) { YunControl(CHCNetSDK.ZOOM_OUT);//- } private void button3_Click_1(object sender, EventArgs e) { YunControl(CHCNetSDK.ZOOM_IN);// } private void button6_Click_1(object sender, EventArgs e) { YunControl(CHCNetSDK.UP_LEFT);//左上 } private void button7_Click_1(object sender, EventArgs e) { YunControl(CHCNetSDK.DOWN_LEFT);//左下 } private void button9_Click_1(object sender, EventArgs e) { YunControl(CHCNetSDK.UP_RIGHT);//右上 } private void button10_Click_1(object sender, EventArgs e) { YunControl(CHCNetSDK.DOWN_RIGHT);//右下 } private void YunControl(uint demo) { try { if (CHCNetSDK.NET_DVR_PTZControl_Other(pLoginID1, 1, demo, 0)) { Thread.Sleep(100); CHCNetSDK.NET_DVR_PTZControl_Other(pLoginID1, 1, CHCNetSDK.PAN_LEFT, 1); } } catch { } } #endregion #region 长按 private bool IsRun = false; private int Con = 0; private void button3_MouseDown_1(object sender, MouseEventArgs e) { Con = 1; timer1.Start(); IsRun = true; } private void button3_MouseUp_1(object sender, MouseEventArgs e) { Con = 0; timer1.Stop(); IsRun = false; ; } private void button1_MouseDown_1(object sender, MouseEventArgs e) { Con = -1; timer1.Start(); IsRun = true; } private void button1_MouseUp_1(object sender, MouseEventArgs e) { Con = 0; timer1.Stop(); IsRun = false; } private void timer1_Tick_1(object sender, EventArgs e) { if (IsRun) { if (Con == 1) YunControl_(CHCNetSDK.ZOOM_IN);// else if (Con == -1) YunControl_(CHCNetSDK.ZOOM_OUT);//- } } private void YunControl_(uint demo) { try { if (CHCNetSDK.NET_DVR_PTZControl_Other(pLoginID1, 1, demo, 0)) { Thread.Sleep(300); CHCNetSDK.NET_DVR_PTZControl_Other(pLoginID1, 1, demo, 1); } } catch { } } #endregion #region 加载配置 private string IP = string.Empty; private int Port = 0; private string Admin = string.Empty; private string Password = string.Empty; private void InitConfig() { try { IP = System.Configuration.ConfigurationManager.AppSettings["IP"].ToString(); Port = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["Port"].ToString()); Admin = System.Configuration.ConfigurationManager.AppSettings["Admin"].ToString(); Password = System.Configuration.ConfigurationManager.AppSettings["Passward"].ToString(); } catch { MessageBox.Show("配置出错"); Application.Exit(); } } #endregion private void pictureBox1_DoubleClick(object sender, EventArgs e) { int loginId = pLoginID1; BigScress frm = new BigScress(loginId, this.BindVideo1); frm.ShowDialog(this); } } }
【程序目录】
└─yundemo
│ .gitattributes
│ .gitignore
│ yundemo.sln
│
└─yundemo
│ App.config
│ BigScress.cs
│ BigScress.Designer.cs
│ BigScress.resx
│ CHCNetSDK.cs
│ Form1.cs
│ Form1.Designer.cs
│ Form1.resx
│ Program.cs
│ WMPlayer.ico
│ yundemo.csproj
│
├─bin
│ ├─Debug
│ │ │ AudioRender.dll
│ │ │ HCCore.dll
│ │ │ HCNetSDK.dll
│ │ │ PlayCtrl.dll
│ │ │ SuperRender.dll
│ │ │ yundemo.exe
│ │ │ yundemo.exe.config
│ │ │ yundemo.pdb
│ │ │
│ │ └─HCNetSDKCom
│ │ AnalyzeData.dll
│ │ AudioIntercom.dll
│ │ HCAlarm.dll
│ │ HCAlarm.lib
│ │ HCCoreDevCfg.dll
│ │ HCDisplay.dll
│ │ HCGeneralCfgMgr.dll
│ │ HCGeneralCfgMgr.lib
│ │ HCIndustry.dll
│ │ HCPlayBack.dll
│ │ HCPreview.dll
│ │ HCPreview.lib
│ │ HCVoiceTalk.dll
│ │ libiconv2.dll
│ │ msvcr90.dll
│ │ OpenAL32.dll
│ │ StreamTransClient.dll
│ │ SystemTransform.dll
│ │
│ └─Release
├─obj
│ └─Debug
│ │ DesignTimeResolveAssemblyReferences.cache
│ │ DesignTimeResolveAssemblyReferencesInput.cache
│ │ TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
│ │ TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
│ │ TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
│ │ yundemo.BigScress.resources
│ │ yundemo.csproj.CoreCompileInputs.cache
│ │ yundemo.csproj.FileListAbsolute.txt
│ │ yundemo.csproj.GenerateResource.cache
│ │ yundemo.csprojAssemblyReference.cache
│ │ yundemo.exe
│ │ yundemo.Form1.resources
│ │ yundemo.pdb
│ │ yundemo.Properties.Resources.resources
│ │
│ └─TempPE
│ Properties.Resources.Designer.cs.dll
│
└─Properties
AssemblyInfo.cs
Resources.Designer.cs
Resources.resx
Settings.Designer.cs
Settings.settings
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论