private int m_lRealHandle; //预览 //注册 private void RegButClick(object sender, EventArgs e) { if (ipaddr.Text == null || port.Text == null) { MessageBox.Show("请输入设备IP地址和端口号"); return; } m_bInitSDK = HKSDK.NET_DVR_Init(); if (!m_bInitSDK) { textBox1.AppendText("\r\n初始化失败"); } else { textBox1.AppendText("\r\n初始化成功");// MessageBox.Show("初始化成功"); } HKSDK.NET_DVR_DEVICEINFO_V30 struDeviceInfo = new HKSDK.NET_DVR_DEVICEINFO_V30(); m_lUserID = HKSDK.NET_DVR_Login_V30(ipaddr.Text, int.Parse(port.Text), "admin", "12345", ref struDeviceInfo); if (m_lUserID < 0) { textBox1.AppendText("\r\n注册失败"); } else { textBox1.AppendText("\r\n注册成功");// MessageBox.Show("注册成功"); } }
//保存图片线程 public void savePicThread( ) { try { picname++; string sBmpPicFileName = savepath + "pic\\" + picname.ToString() + ".jpg"; if (!HKSDK.NET_DVR_CapturePicture(m_lRealHandle, sBmpPicFileName)) { } else { if (this.pictureBox1.InvokeRequired) { pictureBox1.BeginInvoke(new UPdatePicBox(showpic), sBmpPicFileName); } else { showpic(sBmpPicFileName); } } } catch (System.Exception ex) { } }
public void MsgCallback(int lCommand, ref HKSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser) { //通过lCommand来判断接收到的报警信息类型,不同的lCommand对应不同的pAlarmInfo内容 switch (lCommand) { case HKSDK.COMM_UPLOAD_PLATE_RESULT://旧上传 ProcessCommAlarm_Plate(ref pAlarmer, pAlarmInfo, dwBufLen, pUser); break; case HKSDK.COMM_ITS_PLATE_RESULT://新上传 ProcessCommAlarm_ITSPlate(ref pAlarmer, pAlarmInfo, dwBufLen, pUser); break; default: break; } }
private void manualCap(object sender, EventArgs e) { //captag = new HKSDK.tagNET_DVR_SNAPCFG(); //captag.bySnapTimes = 1; //captag.wSnapWaitTime = 1; //ushort[] capnum = new ushort[4]; //capnum[0] = 1; //capnum[1] = 1; //capnum[2] = 2; //capnum[3] = 3; //captag.wIntervalTime = capnum; //captag.byRelatedDriveWay = 0; //captag.dwSize = (uint)Marshal.SizeOf(typeof(HKSDK.tagNET_DVR_SNAPCFG)); //HKSDK.NET_DVR_ContinuousShoot(m_lUserID, ref captag); HKSDK.tagNET_DVR_MANUALSNAP msnap = new HKSDK.tagNET_DVR_MANUALSNAP(); HKSDK.tagNET_DVR_PLATE_RESULT plateres = new HKSDK.tagNET_DVR_PLATE_RESULT(); HKSDK.NET_DVR_ManualSnap(m_lUserID, ref msnap, ref plateres); }
//预览开启 private void previewOpenClick(object sender, EventArgs e) { if (m_lUserID >= 0) { if (button2.Text == @"开启预览") { HKSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new HKSDK.NET_DVR_PREVIEWINFO(); lpPreviewInfo.hPlayWnd = panel1.Handle; //预览窗口 lpPreviewInfo.lChannel = 1; //预te览的设备通道 lpPreviewInfo.dwStreamType = 0; //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推 lpPreviewInfo.dwLinkMode = 0; //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP lpPreviewInfo.bBlocked = true; //0- 非阻塞取流,1- 阻塞取流 IntPtr pUser = new IntPtr(); //用户数据 m_lRealHandle = HKSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null /*RealData*/, pUser); if (m_lRealHandle < 0) { textBox1.AppendText("\r\n开启预览失败"); // MessageBox.Show("error " + HKSDK.NET_DVR_GetLastError()); return; } // savepic = new Thread(new ThreadStart(savePicThread)); m_call = new HKSDK.MSGCallBack(MsgCallback); if (HKSDK.NET_DVR_SetDVRMessageCallBack_V30(m_call, IntPtr.Zero)) { textBox1.AppendText("\r\n开启预览成功"); } button2.Text = @"关闭预览"; } else { HKSDK.NET_DVR_StopRealPlay(m_lRealHandle); button2.Text = @"关闭预览"; textBox1.AppendText("\r\n关闭预览"); } } }
private void CapturePic(object sender, EventArgs e) { if (button4.Text == @"开启抓拍") { HKSDK.tagNET_DVR_SETUPALARM_PARAM starttag = new HKSDK.tagNET_DVR_SETUPALARM_PARAM(); // starttag.dwSize = (uint)Marshal.SizeOf(typeof(HKSDK.NET_DVR_SETUPALARM_PARAM)); starttag.byAlarmInfoType = 1; starttag.byRetAlarmTypeV40 = 1; capparam = HKSDK.NET_DVR_SetupAlarmChan_V41(m_lUserID, ref starttag); textBox1.AppendText("\r\n开启抓拍"); button4.Text = @"关闭抓拍"; } else { HKSDK.NET_DVR_CloseAlarmChan_V30(capparam); textBox1.AppendText("\r\n关闭抓拍"); button4.Text = @"开启抓拍"; } if (m_lRealHandle < 0) { return; } }
/// 新上传处理函数 private void ProcessCommAlarm_ITSPlate(ref HKSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser) { HKSDK.NET_ITS_PLATE_RESULT struITSPlateResult = new HKSDK.NET_ITS_PLATE_RESULT(); uint dwSize = (uint)Marshal.SizeOf(struITSPlateResult); //PtrToStructure返回托管对象 将非托管对象封送到新分配的指定类型的托管 struITSPlateResult = (HKSDK.NET_ITS_PLATE_RESULT)Marshal.PtrToStructure(pAlarmInfo, typeof(HKSDK.NET_ITS_PLATE_RESULT)); //保存抓拍图片 for (int i = 0; i < struITSPlateResult.dwPicNum; i++) { if (struITSPlateResult.struPicInfo[i].dwDataLen != 0) { pictureBox1.Image = Image.FromFile(""); if (InvokeRequired)//非当前线程 { pictureBox1.BeginInvoke(new UpdateListBoxCallback(UpdateClientList)); } else { //当前线程 // UpdateClientList(0,0); } // pictureBox1.Image = Image.FromFile(@"D:\卡口\20150416\20150416163914627.jpg"); } } }
private void ProcessCommAlarm_Plate(ref HKSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser) { try { HKSDK.NET_DVR_PLATE_RESULT struPlateResultInfo = new HKSDK.NET_DVR_PLATE_RESULT(); uint dwSize = (uint)Marshal.SizeOf(struPlateResultInfo); struPlateResultInfo = (HKSDK.NET_DVR_PLATE_RESULT)Marshal.PtrToStructure(pAlarmInfo, typeof(HKSDK.NET_DVR_PLATE_RESULT)); if (struPlateResultInfo.byResultType == 1&&struPlateResultInfo.dwPicLen>0) { byte[] by = new byte[struPlateResultInfo.dwPicLen]; Marshal.Copy(struPlateResultInfo.pBuffer1, by, 0, (int)struPlateResultInfo.dwPicLen); MemoryStream ms = new MemoryStream(by, 0, (int)struPlateResultInfo.dwPicLen); Image returnImage = Image.FromStream(ms); pictureBox1.Image = returnImage; if (filepath.Text != "") { returnImage.Save(filepath.Text+vehnum.ToString()+".jpg"); vehnum++; } } } catch (System.Exception ex) { } }