CameraShotCls.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using Common;
  2. using MeterPlugInLibrary;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9. namespace StorageMeterSystem
  10. {
  11. /// <summary>
  12. /// 截图调用类
  13. /// </summary>
  14. public class CameraShotCls
  15. {
  16. public CameraShotCls()
  17. {
  18. _dvr = new HkDvr();
  19. }
  20. private HkDvr _dvr;
  21. bool ret = false;
  22. public string ip { get; set; }
  23. public string port { get; set; }
  24. public string uid { get; set; }
  25. public string pwd { get; set; }
  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. /// <returns></returns>
  47. public bool StartTalk()
  48. {
  49. if (_dvr.UserId > -1 && !startTalk)
  50. {
  51. _dvr.StartTalk();
  52. startTalk = true;
  53. }
  54. return true;
  55. }
  56. /// <summary>
  57. /// 关闭对讲
  58. /// </summary>
  59. /// <returns></returns>
  60. public bool StopTalk()
  61. {
  62. if (_dvr.UserId > -1 && startTalk)
  63. {
  64. _dvr.StopTalk();
  65. startTalk = false;
  66. return true;
  67. }
  68. return true;
  69. }
  70. /// <summary>
  71. /// 关闭视频
  72. /// </summary>
  73. public void Close()
  74. {
  75. if (_dvr.UserId > -1)
  76. {
  77. _dvr.Close();
  78. }
  79. }
  80. public void RealPlay(PictureBox picture, int i)
  81. {
  82. if (_dvr.UserId > -1)
  83. {
  84. _dvr.RealPlay(i, picture.Handle);
  85. }
  86. }
  87. public void StopRealPlay(int i)
  88. {
  89. if (_dvr.UserId > -1)
  90. {
  91. _dvr.StopRealPlay(i);
  92. }
  93. }
  94. public bool SoundVoice(string fileName)
  95. {
  96. _dvr.SetVolume(0xffff);
  97. if (_dvr.VoiceHandle > -1) //播放语音前,需要关闭对讲
  98. {
  99. _dvr.StopTalk();
  100. }
  101. return _dvr.SendVoiceData(fileName);
  102. }
  103. /// <summary>
  104. /// 从硬盘录像机 进行截图
  105. /// </summary>
  106. /// <param name="fileUrl"></param>
  107. public void CapPicFromVideo(uint chanel,string fileUrl)
  108. {
  109. _dvr.CapturePicture(chanel, fileUrl + ".jpg");
  110. }
  111. #region 直接通过摄像头进行截图的方式
  112. /// <summary>
  113. /// 连接视频截图并关闭
  114. /// </summary>
  115. /// <param name="actualFirstNo">作业编号</param>
  116. public void CapMethod(string actualFirstNo)
  117. {
  118. Connection();
  119. CapPic(actualFirstNo);
  120. Close();
  121. }
  122. /// <summary>
  123. /// 截图
  124. /// </summary>
  125. /// <param name="actualFirstNo">作业编号</param>
  126. public void CapPic(string actualFirstNo)
  127. {
  128. int iCnt = 1; //抓拍摄像头配置顺序必须是前面2个
  129. foreach (CameraShotCls shot in CarCache.cameraShots)
  130. {
  131. //放在tempImg文件夹下面就进行图片的压缩操作,否则不进行图片压缩
  132. shot.CapPic(iCnt < 3 ? 0 : 1, PbCache.path + string.Format("\\imgShort\\formalImg\\{0}_{1}_{2}.jpg", PbCache.sportInfo.baseSpotNo, "C" + actualFirstNo, iCnt));
  133. iCnt++;
  134. }
  135. }
  136. /// <summary>
  137. /// 截图
  138. /// </summary>
  139. /// <param name="voiType">0抓拍机 1一般的摄像头</param>
  140. /// <param name="filePath">文件存储位置及文件名称,文件名称应该是 计量作业编号_计量点_第几张 or 计量作业编号_第几张</param>
  141. /// <returns>是否截图成功,true成功,false失败,异常的话会在logs中写入信息</returns>
  142. public bool CapPic(int voiType, string filePath)
  143. {
  144. return _dvr.CapturePicture(voiType, 1, filePath);
  145. }
  146. #endregion
  147. }
  148. public class CarCache
  149. {
  150. /// <summary>
  151. /// 摄像头的开关类集合
  152. /// </summary>
  153. public static List<CameraShotCls> cameraShots { get; set; }
  154. }
  155. }