using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace MeterPlugInLibrary { /// /// 海康摄像头截图 /// public class DhCameraShot { private HkDvr _dvr; public DhCameraShot() { _dvr = new HkDvr(); } bool ret = false; public string ip { get; set; } public string port { get; set; } public string uid { get; set; } public string pwd { get; set; } /// /// 连接设备 /// /// IP地址 /// 端口 /// 用户名 /// 密码 public void Connection() { if (_dvr.UserId < 0) { //IP,PORT,UID,PWD ret = _dvr.Init(ip + "," + port + "," + uid + "," + pwd); ret = _dvr.Open(); } } private bool startTalk = false; /// /// 打开对讲 /// /// public bool StartTalk() { if (_dvr.UserId > -1 && !startTalk) { _dvr.StartTalk(); startTalk = true; } return true; } /// /// 关闭对讲 /// /// public bool StopTalk() { if (_dvr.UserId > -1 && startTalk) { _dvr.StopTalk(); startTalk = false; return true; } return true; } /// /// 关闭视频 /// public void Close() { if (_dvr.UserId > -1) { _dvr.Close(); } } public void RealPlay(PictureBox picture, int i) { if (_dvr.UserId > -1) { _dvr.RealPlay(i, picture.Handle); } } public void StopRealPlay(int i) { if (_dvr.UserId > -1) { _dvr.StopRealPlay(i); } } /// /// 截图 /// /// 0抓拍机 1一般的摄像头 /// 文件存储位置及文件名称,文件名称应该是 计量作业编号_计量点_第几张 or 计量作业编号_第几张 /// 是否截图成功,true成功,false失败,异常的话会在logs中写入信息 public bool CapPic(int voiType, string filePath) { return _dvr.CapturePicture(voiType, 1, filePath); /* _dvr.CapturePicture(1, 1, filePath); _dvr.CapturePicture(1, 2, filePath.Substring(0, filePath.Length - 5) + "2.jpg"); _dvr.CapturePicture(1, 3, filePath.Substring(0, filePath.Length - 5) + "3.jpg"); _dvr.CapturePicture(1, 4, filePath.Substring(0, filePath.Length - 5) + "4.jpg"); _dvr.CapturePicture(1, 5, filePath.Substring(0, filePath.Length - 5) + "5.jpg"); _dvr.CapturePicture(1, 6, filePath.Substring(0, filePath.Length - 5) + "6.jpg"); return true; //*/ } public bool CapPicFromVedio(uint chanel, string filePath) { try { return _dvr.CapturePicture(chanel, filePath + chanel + ".jpg"); } catch (Exception) { return false; } } /// /// 硬盘录像机截图 /// /// /// public bool CapPicFromVedio(string filePath) { try { bool a1 = _dvr.CapturePicture(1, filePath + "1.jpg"); bool a2 = _dvr.CapturePicture(2, filePath + "2.jpg"); bool a3 = _dvr.CapturePicture(3, filePath + "3.jpg"); bool a4 = _dvr.CapturePicture(4, filePath + "4.jpg"); bool a5 = _dvr.CapturePicture(5, filePath + "5.jpg"); bool a6 = _dvr.CapturePicture(6, filePath + "6.jpg"); return true; } catch (Exception) { return false; } /* _dvr.CapturePicture(1, 1, filePath); _dvr.CapturePicture(1, 2, filePath.Substring(0, filePath.Length - 5) + "2.jpg"); _dvr.CapturePicture(1, 3, filePath.Substring(0, filePath.Length - 5) + "3.jpg"); _dvr.CapturePicture(1, 4, filePath.Substring(0, filePath.Length - 5) + "4.jpg"); _dvr.CapturePicture(1, 5, filePath.Substring(0, filePath.Length - 5) + "5.jpg"); _dvr.CapturePicture(1, 6, filePath.Substring(0, filePath.Length - 5) + "6.jpg"); return true; //*/ } } }