CamerEs.cs 4.6 KB

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