DhCameraShot.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. namespace MeterPlugInLibrary
  8. {
  9. /// <summary>
  10. /// 海康摄像头截图
  11. /// </summary>
  12. public class DhCameraShot
  13. {
  14. private HkDvr _dvr;
  15. public DhCameraShot()
  16. {
  17. _dvr = new HkDvr();
  18. }
  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="voiType">0抓拍机 1一般的摄像头</param>
  96. /// <param name="filePath">文件存储位置及文件名称,文件名称应该是 计量作业编号_计量点_第几张 or 计量作业编号_第几张</param>
  97. /// <returns>是否截图成功,true成功,false失败,异常的话会在logs中写入信息</returns>
  98. public bool CapPic(int voiType, string filePath)
  99. {
  100. return _dvr.CapturePicture(voiType, 1, filePath);
  101. /*
  102. _dvr.CapturePicture(1, 1, filePath);
  103. _dvr.CapturePicture(1, 2, filePath.Substring(0, filePath.Length - 5) + "2.jpg");
  104. _dvr.CapturePicture(1, 3, filePath.Substring(0, filePath.Length - 5) + "3.jpg");
  105. _dvr.CapturePicture(1, 4, filePath.Substring(0, filePath.Length - 5) + "4.jpg");
  106. _dvr.CapturePicture(1, 5, filePath.Substring(0, filePath.Length - 5) + "5.jpg");
  107. _dvr.CapturePicture(1, 6, filePath.Substring(0, filePath.Length - 5) + "6.jpg");
  108. return true;
  109. //*/
  110. }
  111. public bool CapPicFromVedio(uint chanel, string filePath)
  112. {
  113. try
  114. {
  115. return _dvr.CapturePicture(chanel, filePath + chanel + ".jpg");
  116. }
  117. catch (Exception)
  118. {
  119. return false;
  120. }
  121. }
  122. /// <summary>
  123. /// 硬盘录像机截图
  124. /// </summary>
  125. /// <param name="filePath"></param>
  126. /// <returns></returns>
  127. public bool CapPicFromVedio(string filePath)
  128. {
  129. try
  130. {
  131. bool a1 = _dvr.CapturePicture(1, filePath + "1.jpg");
  132. bool a2 = _dvr.CapturePicture(2, filePath + "2.jpg");
  133. bool a3 = _dvr.CapturePicture(3, filePath + "3.jpg");
  134. bool a4 = _dvr.CapturePicture(4, filePath + "4.jpg");
  135. bool a5 = _dvr.CapturePicture(5, filePath + "5.jpg");
  136. bool a6 = _dvr.CapturePicture(6, filePath + "6.jpg");
  137. return true;
  138. }
  139. catch (Exception)
  140. {
  141. return false;
  142. }
  143. /*
  144. _dvr.CapturePicture(1, 1, filePath);
  145. _dvr.CapturePicture(1, 2, filePath.Substring(0, filePath.Length - 5) + "2.jpg");
  146. _dvr.CapturePicture(1, 3, filePath.Substring(0, filePath.Length - 5) + "3.jpg");
  147. _dvr.CapturePicture(1, 4, filePath.Substring(0, filePath.Length - 5) + "4.jpg");
  148. _dvr.CapturePicture(1, 5, filePath.Substring(0, filePath.Length - 5) + "5.jpg");
  149. _dvr.CapturePicture(1, 6, filePath.Substring(0, filePath.Length - 5) + "6.jpg");
  150. return true;
  151. //*/
  152. }
  153. }
  154. }