DhCameraShot.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Windows.Forms;
  7. namespace Core.StlMes.Client.LgResMgt.Mcms
  8. {
  9. /// <summary>
  10. /// 海康摄像头截图
  11. /// </summary>
  12. public class DhCameraShot
  13. {
  14. public DhCameraShot()
  15. {
  16. _dvr = new HkDvr();
  17. }
  18. private HkDvr _dvr;
  19. bool ret = false;
  20. public string ip { get; set; }
  21. public string port { get; set; }
  22. public string uid { get; set; }
  23. public string pwd { get; set; }
  24. /// <summary>
  25. /// 连接设备
  26. /// </summary>
  27. /// <param name="Ip">IP地址</param>
  28. /// <param name="Port">端口</param>
  29. /// <param name="Uid">用户名</param>
  30. /// <param name="Pwd">密码</param>
  31. public void Connection()
  32. {
  33. if (_dvr.UserId < 0)
  34. {
  35. //IP,PORT,UID,PWD
  36. ret = _dvr.Init(ip + "," + port + "," + uid + "," + pwd);
  37. ret = _dvr.Open();
  38. }
  39. }
  40. private bool startTalk = false;
  41. /// <summary>
  42. /// 打开对讲
  43. /// </summary>
  44. /// <returns></returns>
  45. //public bool StartTalk()
  46. //{
  47. // if (_dvr.UserId > -1 && !startTalk)
  48. // {
  49. // _dvr.StartTalk();
  50. // startTalk = true;
  51. // }
  52. // return true;
  53. //}
  54. /// <summary>
  55. /// 关闭对讲
  56. /// </summary>
  57. /// <returns></returns>
  58. public bool StopTalk()
  59. {
  60. if (_dvr.UserId > -1 && startTalk)
  61. {
  62. // _dvr.StopTalk();
  63. startTalk = false;
  64. return true;
  65. }
  66. return true;
  67. }
  68. /// <summary>
  69. /// 关闭视频
  70. /// </summary>
  71. public void Close()
  72. {
  73. if (_dvr.UserId > -1)
  74. {
  75. _dvr.Close();
  76. }
  77. }
  78. public void RealPlay(PictureBox picture, int i)
  79. {
  80. if (_dvr.UserId > -1)
  81. {
  82. _dvr.RealPlay(i, picture.Handle);
  83. }
  84. }
  85. public void StopRealPlay(int i)
  86. {
  87. if (_dvr.UserId > -1)
  88. {
  89. _dvr.StopRealPlay(i);
  90. }
  91. }
  92. /// <summary>
  93. /// 截图
  94. /// </summary>
  95. /// <param name="filePath">文件存储位置及文件名称,文件名称应该是 计量作业编号_计量点_第几张 or 计量作业编号_第几张</param>
  96. /// <returns>是否截图成功,true成功,false失败,异常的话会在logs中写入信息</returns>
  97. //public bool CapPic(int channel, string filePath)
  98. //{
  99. // // return _dvr.CapturePicture((uint)channel, 1, filePath);//默认为一般摄像头
  100. // //_dvr.CapturePicture(1, 1, filePath);
  101. // //_dvr.CapturePicture(1, 2, filePath.Substring(0, filePath.Length - 5) + "2.jpg");
  102. // //_dvr.CapturePicture(1, 3, filePath.Substring(0, filePath.Length - 5) + "3.jpg");
  103. // //_dvr.CapturePicture(1, 4, filePath.Substring(0, filePath.Length - 5) + "4.jpg");
  104. // //_dvr.CapturePicture(1, 5, filePath.Substring(0, filePath.Length - 5) + "5.jpg");
  105. // //_dvr.CapturePicture(1, 6, filePath.Substring(0, filePath.Length - 5) + "6.jpg");
  106. // //return true;
  107. //}
  108. public bool CapPicFromVedio(uint chanel, string filePath)
  109. {
  110. try
  111. {
  112. return _dvr.CapturePicture(chanel, filePath + chanel + ".jpg");
  113. }
  114. catch (Exception)
  115. {
  116. return false;
  117. }
  118. }
  119. /// <summary>
  120. /// 硬盘录像机截图
  121. /// </summary>
  122. /// <param name="filePath"></param>
  123. /// <returns></returns>
  124. Thread th;
  125. public bool CapPicFromVedio(string filePath)
  126. {
  127. th = new Thread(new ParameterizedThreadStart(CapPicFromVed));
  128. th.Start(filePath);
  129. return true;
  130. }
  131. void CapPicFromVed(object filePath)
  132. {
  133. try
  134. {
  135. bool a1 = _dvr.CapturePicture(1, filePath + "1.jpg");
  136. bool a2 = _dvr.CapturePicture(2, filePath + "2.jpg");
  137. bool a3 = _dvr.CapturePicture(3, filePath + "3.jpg");
  138. bool a4 = _dvr.CapturePicture(4, filePath + "4.jpg");
  139. //bool a5 = _dvr.CapturePicture(5, filePath + "5.jpg");
  140. //bool a6 = _dvr.CapturePicture(6, filePath + "6.jpg");
  141. }
  142. catch (Exception)
  143. {
  144. }
  145. CHCNetSDK.NET_DVR_GetLastError();
  146. }
  147. public bool PlayMusic(string path )
  148. {
  149. return _dvr.G711VoiceCom(path);
  150. // return _dvr.SendVoiceData(path);
  151. }
  152. }
  153. }