/// <summary> /// 显示摄像头 /// </summary> protected void ShowCamera(Border CameraBorder, StackPanel CameraStackPanel, IconButton settingVideoBtn) { if (mCameraInfos.Count <= 0) { settingVideoBtn.Visibility = Visibility.Visible; return; } this.Cursor = Cursors.Wait; CameraPanelWidth = CameraBorder.ActualWidth; CameraWidth = Math.Floor(CameraPanelWidth / mCameraInfos.Count); CameraHeight = CameraBorder.ActualHeight - 2; CameraStackPanel.Children.Clear(); if (CameraHelper.InitSDK() == false) { MessageBox.Show("摄像头SDK初始化失败!"); return; } if (CameraIds == null) { CameraIds = new List <int>(); } else { StorpPreviewCamera(); LogoutCamera(); CameraIds.Clear(); } if (mPictureBoxs == null) { mPictureBoxs = new List <System.Windows.Forms.PictureBox>(); } else { mPictureBoxs.Clear(); } if (mDeviceInfors == null) { mDeviceInfors = new List <CHCNetSDK.NET_DVR_DEVICEINFO_V30>(); } else { mDeviceInfors.Clear(); } for (int i = 0; i < mCameraInfos.Count; i++) { try { CameraInfo camera = mCameraInfos[i]; System.Windows.Forms.Integration.WindowsFormsHost windowsFormsHost = new System.Windows.Forms.Integration.WindowsFormsHost() { Name = $"WFH{i}" }; System.Windows.Forms.PictureBox pictureBox = new System.Windows.Forms.PictureBox() { Name = $"pictureBox{i}", Width = (int)CameraWidth, Height = (int)CameraHeight }; mPictureBoxs.Add(pictureBox); CHCNetSDK.NET_DVR_DEVICEINFO_V30 deviceinfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30(); //login int cameraid = CameraHelper.loginCamera(camera.ip, camera.port, camera.userName, camera.password, ref deviceinfo); if (cameraid <= -1) { throw new Exception("登陆失败"); } CameraIds.Add(cameraid); mDeviceInfors.Add(deviceinfo); //preview int ChanNum = deviceinfo.byChanNum; int streamType = Convert.ToInt32(ConfigurationHelper.GetConfig(ConfigItemName.cameraStramType.ToString())); bool res = CameraHelper.Preview(ref pictureBox, ChanNum, cameraid, streamType); windowsFormsHost.Child = pictureBox; CameraStackPanel.Children.Add(windowsFormsHost); } catch { TextBlock textBlock = new TextBlock(); textBlock.Width = CameraWidth; //textBlock.Height = CameraHeight; textBlock.TextAlignment = TextAlignment.Center; textBlock.HorizontalAlignment = HorizontalAlignment.Center; textBlock.VerticalAlignment = VerticalAlignment.Bottom; textBlock.Text = "视频加载失败"; textBlock.FontSize = 16; textBlock.Foreground = System.Windows.Media.Brushes.Red; CameraStackPanel.Children.Add(textBlock); } } this.Cursor = Cursors.Arrow; }
private void saveBtn_Click(object sender, RoutedEventArgs e) { //抓图 //if (isInitSDK && isPreviewSuccess) { // CameraHelper.captureJpeg(Guid.NewGuid().ToString()+".jpg",currCameraId,1); // CameraHelper.captureBmp(Guid.NewGuid().ToString() + ".bmp",currCameraId); //}else{ // ConsoleHelper.writeLine("captureJpeg failured"); //} if (!IsInitialized) { MessageBox.Show("摄像头初始化失败!"); return; } if (!isPreviewSuccess) { MessageBox.Show("保存摄像头之前必须先预览成功!"); return; } if (checkInput()) { String condition = String.Empty; String sql = string.Empty; if (!String.IsNullOrEmpty(mId)) { //update mCameraInfo.syncTime = (int)DateTimeHelper.GetTimeStamp(); mCameraInfo.ip = this.IpTB.Text.Trim(); mCameraInfo.port = this.portTB.Text.Trim(); mCameraInfo.userName = this.userNameTB.Text.Trim(); mCameraInfo.password = this.pwdTB.Text.Trim(); int res = DatabaseOPtionHelper.GetInstance().update(mCameraInfo); if (res > 0) { MessageBox.Show("修改成功!"); this.Close(); } else { MessageBox.Show("修改失败!"); return; } } else { //insert CameraInfo camera = new CameraInfo(); string cid = ConfigurationHelper.GetConfig(ConfigItemName.clientId.ToString()); condition = CameraInfoEnum.client_id.ToString() + "=" + Constract.valueSplit + cid + Constract.valueSplit + " and " + CameraInfoEnum.ip.ToString() + "=" + Constract.valueSplit + IpTB.Text.ToString() + Constract.valueSplit + " and " + CameraInfoEnum.port.ToString() + "=" + Constract.valueSplit + this.portTB.Text.ToString() + Constract.valueSplit; sql = DatabaseOPtionHelper.GetInstance().getSelectSqlNoSoftDeleteCondition(DatabaseOPtionHelper.GetInstance().getTableName(camera), null, condition, null, null, null, 1, 0); SqlDao.DbHelper optionHelper = DatabaseOPtionHelper.GetInstance(); List <CameraInfo> list = optionHelper.select <CameraInfo>(sql); if (list.Count > 0) { MessageBox.Show("该摄像头已经存在,不要再添加拉!"); return; } else { camera.clientId = cid; camera.companyId = ConfigurationHelper.GetConfig(ConfigItemName.companyId.ToString()); camera.status = 0; camera.isDelete = 0; camera.syncTime = 0; camera.ip = this.IpTB.Text.Trim(); camera.port = this.portTB.Text.Trim(); camera.userName = this.userNameTB.Text.Trim(); camera.password = this.pwdTB.Text.Trim(); camera.id = Guid.NewGuid().ToString(); int res = optionHelper.insert(camera); if (res > 0) { MessageBox.Show("保存成功!"); this.Close(); } else { MessageBox.Show("保存失败!"); return; } } } } }