Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2017
1,173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 31.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using System.Timers;
  6. using DHNetSDK;
  7. using System.Runtime.InteropServices;
  8. using System.Threading;
  9.  
  10. namespace SDKCapturePicture
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         private static System.Timers.Timer aTimer;
  15.         public string arg_ip = Environment.GetCommandLineArgs()[1];
  16.         public string arg_port = Environment.GetCommandLineArgs()[2];
  17.         public string arg_login = Environment.GetCommandLineArgs()[3];
  18.         public string arg_password = Environment.GetCommandLineArgs()[4];
  19.          public Form1()
  20.         {
  21.             aTimer = new System.Timers.Timer();
  22.             aTimer.Interval = 60000;
  23.  
  24.             // Hook up the Elapsed event for the timer.
  25.             aTimer.Elapsed += OnTimedEvent;
  26.  
  27.             // Have the timer fire repeated events (true is the default)
  28.             aTimer.AutoReset = true;
  29.  
  30.             // Start the timer
  31.             aTimer.Enabled = true;
  32.  
  33.             InitializeComponent();
  34.             this.textBoxIP.Text = arg_ip;
  35.             this.textBoxPort.Text = arg_port;
  36.             this.textBoxUser.Text = arg_login;
  37.             this.textBoxPsw.Text = arg_password;
  38.             this.textBoxSerial.Text = "1";
  39.             m_bEnable = false;
  40.  
  41.             m_nLoginID = 0;
  42.             m_bInit = false;
  43.             //this.Login.Enabled = true;
  44.            // this.Logout.Enabled = false;
  45.             this.radioButtonOne.Checked = true;
  46.  
  47.             m_stuSnapCfg = new DHDEV_SNAP_CFG[32];
  48.             for (int i = 0; i < 32; ++i )
  49.             {
  50.                 m_stuSnapCfg[i].struSnapEnc = new DH_VIDEOENC_OPT[32];
  51.             }
  52.  
  53.             m_stuSnapAttr = new DH_SNAP_ATTR_EN();
  54.             m_stuSnapAttr.stuSnap = new DH_QUERY_SNAP_INFO[16];
  55.  
  56.             m_stuSnapAttrEx = new DH_SNAP_ATTR_EN_EX();
  57.             m_stuSnapAttrEx.m_bQueried = new Int32[32];
  58.             m_stuSnapAttrEx.m_stuSnapAttrEx = new CFG_SNAPCAPINFO_INFO[32];
  59.  
  60.             //分辨率
  61.             m_dicPix = new Dictionary<string, int>();
  62.             m_dicPix["D1"] = 0;
  63.             m_dicPix["HD1"] = 1;
  64.             m_dicPix["BCIF"] = 2;
  65.             m_dicPix["CIF"] = 3;
  66.             m_dicPix["QCIF"] = 4;
  67.             m_dicPix["VGA"] = 5;
  68.             m_dicPix["QVGA"] = 6;
  69.             m_dicPix["SVCD"] = 7;
  70.             m_dicPix["QQVGA"] = 8;
  71.             m_dicPix["SVGA"] = 9;
  72.             m_dicPix["XVGA"] = 10;
  73.             m_dicPix["WXGA"] = 11;
  74.             m_dicPix["SXGA"] = 12;
  75.             m_dicPix["WSXGA"] = 13;
  76.             m_dicPix["UXGA"] = 14;
  77.             m_dicPix["WUXGA"] = 15;
  78.             m_dicPix["LTF"] = 16;
  79.             m_dicPix["720p"] = 17;
  80.             m_dicPix["1080p"] = 18;
  81.             m_dicPix["1.3M"] = 19;
  82.             m_dicPix["NR"] = 20;
  83.  
  84.             m_dicQuality = new Dictionary<string, int>();
  85.             m_dicSnapSpace = new Dictionary<string, int>();
  86.             m_dicSnapMode = new Dictionary<string, int>();
  87.                        
  88.             InitSDK();
  89.  
  90.            
  91.  
  92.  
  93.         }
  94.  
  95.         private static void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
  96.         {
  97.             Application.Exit();
  98.         }
  99.  
  100.  
  101.         private void InitSDK()
  102.         {
  103.             m_disConnect = new fDisConnect(DisConnectEvent);
  104.             m_SnapRecv = new fSnapRev(SnapRev);
  105.             m_bInit = DHClient.DHInit(m_disConnect, IntPtr.Zero);
  106.             if (!m_bInit)
  107.             {
  108.              //   MessageBox.Show("初始化失败");
  109.             }
  110.             else
  111.             {
  112.                 DHClient.DHSetSnapRevCallBack(m_SnapRecv, 0);
  113.             }
  114.  
  115.            
  116.             this.Load += new System.EventHandler(this.button1_Click);
  117.         }
  118.  
  119.         //Event Handler
  120.         private void button1_Click(object sender, EventArgs e)
  121.         {
  122.             Login.PerformClick();
  123.         }
  124.  
  125.         private void Login_Click(object sender, EventArgs e)
  126.         {
  127.  
  128.             if (!m_bInit)
  129.             {
  130.                 //  MessageBox.Show("Проблемы с DDL SDK");
  131.                 Application.Exit();
  132.                 return;
  133.             }
  134.  
  135.             //设备用户信息获得
  136.             NET_DEVICEINFO deviceInfo = new NET_DEVICEINFO();
  137.             int error = 0;
  138.             m_nLoginID = DHClient.DHLogin(this.textBoxIP.Text.ToString(), ushort.Parse(this.textBoxPort.Text.ToString()),
  139.                         this.textBoxUser.Text.ToString(), this.textBoxPsw.Text.ToString(), out deviceInfo, out error);
  140.  
  141.             if (m_nLoginID > 0)
  142.             {
  143.                 //this.Login.Enabled = false;
  144.               //  this.Logout.Enabled = true;
  145.                 m_nChannelNum = deviceInfo.byChanNum;
  146.                 for (int i = 0; i < m_nChannelNum; ++i )
  147.                 {
  148.                     this.comboBoxChannel.Items.Add(i.ToString());
  149.                 }
  150.                
  151.                 //query json ability.
  152.                 Int32 dwRetLen = 0;
  153.                 IntPtr pDevEnable = new IntPtr();
  154.                 pDevEnable = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DH_DEV_ENABLE_INFO)));
  155.                 bool bRet = DHClient.DHQuerySystemInfo(m_nLoginID, DH_SYS_ABILITY.ABILITY_DEVALL_INFO, pDevEnable,
  156.                                                 Marshal.SizeOf(typeof(DH_DEV_ENABLE_INFO)), ref dwRetLen, 1000);
  157.                 if (bRet == false)
  158.                 {
  159.                     //MessageBox.Show(ConvertString("Query device ability failed."));
  160.                     // MessageBox.Show("查询设备能力失败");
  161.                     Application.Exit();
  162.                     return;
  163.                 }
  164.  
  165.  
  166.                 DH_DEV_ENABLE_INFO devEnable = new DH_DEV_ENABLE_INFO();
  167.                 devEnable = (DH_DEV_ENABLE_INFO)Marshal.PtrToStructure(pDevEnable, typeof(DH_DEV_ENABLE_INFO));
  168.                 m_bJSON = devEnable.IsFucEnable[(Int32)DH_FUN_SUPPORT.EN_JSON_CONFIG] > 0 ? true : false;
  169.  
  170.                  if (m_bJSON == false)
  171.                  {
  172.                      int nRetLen = 0;
  173.                      IntPtr pStuSnapAttr = new IntPtr();
  174.                      pStuSnapAttr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DH_SNAP_ATTR_EN)));
  175.                      bool nRet = DHClient.DHQueryDevState(m_nLoginID, (int)DHClient.DH_DEVSTATE_SNAP
  176.                                                         , pStuSnapAttr, Marshal.SizeOf(typeof(DH_SNAP_ATTR_EN)) , ref nRetLen, 1000);
  177.                      if (nRet == false || nRetLen != Marshal.SizeOf(typeof(DH_SNAP_ATTR_EN)))
  178.                      {
  179.                         //   MessageBox.Show("获取抓图能力集失败!");
  180.                         Application.Exit();
  181.                         return;
  182.                      }
  183.                      else
  184.                      {
  185.                          m_stuSnapAttr = (DH_SNAP_ATTR_EN)Marshal.PtrToStructure(pStuSnapAttr, typeof(DH_SNAP_ATTR_EN));
  186.                      }
  187.  
  188.                    
  189.                 }
  190.                  else//json
  191.                  {
  192.                      InitSnapConfigExUI(0);
  193.                  }
  194.  
  195.                  IntPtr pSnapCfg = new IntPtr();
  196.                  pSnapCfg = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DHDEV_SNAP_CFG)) * 32);
  197.                  UInt32 dwRetConfig = 0;
  198.                  bRet = DHClient.DHGetDevConfig(m_nLoginID, CONFIG_COMMAND.DH_DEV_SNAP_CFG, -1, pSnapCfg, (UInt32)Marshal.SizeOf(typeof(DHDEV_SNAP_CFG)) * 32, ref dwRetConfig, 1000);
  199.                  if (!bRet)
  200.                  {
  201.                     //   MessageBox.Show("获取抓图配置失败!");
  202.                     Application.Exit();
  203.                     return;
  204.                  }
  205.                  else
  206.                  {
  207.                      for (int i = 0; i < 32; ++i )
  208.                      {
  209.                          m_stuSnapCfg[i] = (DHDEV_SNAP_CFG)Marshal.PtrToStructure((IntPtr)((UInt32)pSnapCfg+i*Marshal.SizeOf(typeof(DHDEV_SNAP_CFG)))
  210.                                                                     , typeof(DHDEV_SNAP_CFG));
  211.                      }
  212.                  }
  213.  
  214.                  if (this.comboBoxChannel.Items.Count > 0)
  215.                  {
  216.                      this.comboBoxChannel.SelectedIndex = 0;
  217.                  }
  218.                  
  219.  
  220.  
  221.                  //this.buttonGet.Enabled = true;
  222.                  //this.buttonSet.Enabled = true;
  223.                 // this.buttonStart.Enabled = true;
  224.                 // this.buttonStop.Enabled = true;
  225.  
  226.  
  227.                 buttonStart.PerformClick();
  228.              }
  229.             else
  230.             {
  231.                 Application.Exit();
  232.             }
  233.  
  234.  
  235.         }
  236.  
  237.         private void Logout_Click(object sender, EventArgs e)
  238.         {
  239.             if (!m_bInit)
  240.             {
  241.                 return;
  242.             }
  243.             if (m_nLoginID > 0 )
  244.             {
  245.                 DHClient.DHLogout(m_nLoginID);
  246.                 m_nLoginID = 0;
  247.             }
  248.  
  249.           //  this.Login.Enabled = true;
  250.          //   this.Logout.Enabled = false;
  251.  
  252.             this.comboBoxChannel.Text = "";
  253.             this.comboBoxChannel.Items.Clear();
  254.             this.comboBoxQuality.Text = "";
  255.             this.comboBoxQuality.Items.Clear();
  256.             this.comboBoxRe.Text = "";
  257.             this.comboBoxRe.Items.Clear();
  258.             this.comboBoxSnapMode.Text = "";
  259.             this.comboBoxSnapMode.Items.Clear();
  260.             this.comboBoxSnapSpace.Text = "";
  261.             this.comboBoxSnapSpace.Items.Clear();
  262.  
  263.         //    this.buttonGet.Enabled = false;
  264.           //  this.buttonSet.Enabled = false;
  265.           //  this.buttonStart.Enabled = false;
  266.           //  this.buttonStop.Enabled = false;
  267.  
  268.         }
  269.  
  270.         private void buttonGet_Click(object sender, EventArgs e)
  271.         {
  272.             UInt32 dwRetLen = 0;
  273.             IntPtr pSnapCfg = new IntPtr();
  274.             pSnapCfg = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DHDEV_SNAP_CFG)) * 32);
  275.             bool bRet = DHClient.DHGetDevConfig(m_nLoginID, CONFIG_COMMAND.DH_DEV_SNAP_CFG, 0, pSnapCfg, (UInt32)Marshal.SizeOf(typeof(DHDEV_SNAP_CFG)) * 32, ref dwRetLen, 1000);
  276.             if (!bRet)
  277.             {
  278.                 //AfxMessageBox(ConvertString("Get snap configure failed."));
  279.                 //  MessageBox.Show("获取抓图配置失败!");
  280.                // Application.Exit();
  281.                 return;
  282.             }
  283.             else
  284.             {
  285.                 for (int i = 0; i < 32; ++i)
  286.                 {
  287.                     m_stuSnapCfg[i] = (DHDEV_SNAP_CFG)Marshal.PtrToStructure((IntPtr)((UInt32)pSnapCfg + i * Marshal.SizeOf(typeof(DHDEV_SNAP_CFG)))
  288.                                                                , typeof(DHDEV_SNAP_CFG));
  289.                 }
  290.             }
  291.  
  292.             OnSelchangeComboChannel(null, null);
  293.         }
  294.  
  295.         private void buttonSet_Click(object sender, EventArgs e)
  296.         {
  297.             int nIndex = this.comboBoxChannel.SelectedIndex;// m_ctlChannel.GetCurSel();
  298.             if (nIndex < 0)
  299.             {
  300.                 return;
  301.             }
  302.             int nChn = nIndex;// m_ctlChannel.GetItemData(nIndex);
  303.  
  304.             IntPtr pSnapCfg = new IntPtr();
  305.             pSnapCfg = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DHDEV_SNAP_CFG)) * 32);
  306.             for (int i = 0; i < 32; ++i )
  307.             {
  308.                 Marshal.StructureToPtr(m_stuSnapCfg[i]
  309.                     , (IntPtr)((UInt32)pSnapCfg + i * Marshal.SizeOf(typeof(DHDEV_SNAP_CFG))), false);
  310.             }
  311.  
  312.             bool bRet = DHClient.DHSetDevConfig(m_nLoginID, CONFIG_COMMAND.DH_DEV_SNAP_CFG, nChn, pSnapCfg, (UInt32)Marshal.SizeOf(typeof(DHDEV_SNAP_CFG)) * 32, 1000);
  313.             if (!bRet)
  314.             {
  315.                 //AfxMessageBox(ConvertString("Set snap configure failed!"));
  316.                 // MessageBox.Show("保存抓图配置失败!");
  317.                
  318.             }
  319.         }
  320.  
  321.         private void buttonStart_Click(object sender, EventArgs e)
  322.         {
  323.             if (0 != m_nLoginID)
  324.             {
  325.  
  326.                 if (m_snapmode == -1)
  327.                 {
  328.                     //MessageBox(ConvertString("please select snap mode!"), ConvertString("prompt"));
  329.                     return;
  330.                 }
  331.                
  332.                 for (int i = 0; i <= comboBoxChannel.Items.Count; i++)
  333.  
  334.                 {
  335.  
  336.                     //Fill in request structure
  337.                 SNAP_PARAMS snapparams = new SNAP_PARAMS();
  338.                 snapparams.Channel = (UInt32)i;
  339.                 snapparams.mode = this.radioButtonOne.Checked ? 0 : 1;//m_snapmode>0?0:1;
  340.                 snapparams.CmdSerial = UInt32.Parse(this.textBoxSerial.Text.ToString());
  341.  
  342.                 if (snapparams.mode == 1)
  343.                 {
  344.                     //Time interval for scheduled snapshot. Use snapshot setup to configure.
  345.                     snapparams.InterSnap = (UInt32)m_dicSnapSpace[this.comboBoxSnapSpace.Text.ToString()];
  346.                 }
  347.  
  348.                 bool bRet = DHClient.DHSnapPicture(m_nLoginID, snapparams);
  349.                 if (!bRet)
  350.                 {
  351.                     // MessageBox.Show("抓图启动失败");
  352.                 }
  353.                 else
  354.                 {
  355.                     //  MessageBox.Show("抓图启动成功");
  356.                 }
  357.                
  358.  
  359.                }
  360.             }
  361.         }
  362.  
  363.         private void buttonStop_Click(object sender, EventArgs e)
  364.         {
  365.             if (0 == m_nLoginID)
  366.             {
  367.                 return;
  368.             }
  369.  
  370.             //Fill in stop request.
  371.             SNAP_PARAMS snapparams = new SNAP_PARAMS();
  372.             snapparams.mode = -1;
  373.             snapparams.Channel = (UInt32)this.comboBoxChannel.SelectedIndex;
  374.             snapparams.CmdSerial = UInt32.Parse(this.textBoxSerial.Text.ToString());
  375.  
  376.             bool b = DHClient.DHSnapPicture(m_nLoginID, snapparams);
  377.             if (!b)
  378.             {
  379.                // MessageBox.Show("停止抓图失败");
  380.             }
  381.             else
  382.             {
  383.                // MessageBox.Show("停止抓图成功");
  384.             }
  385.         }
  386.  
  387.         private void OnSelchangeComboChannel(object sender, EventArgs e)
  388.         {
  389.             // TODO: Add your control notification handler code here
  390.             int nIndex = this.comboBoxChannel.SelectedIndex;
  391.            
  392.             if(nIndex < 0)
  393.             {
  394.                 return;
  395.             }
  396.             int nChn = nIndex;
  397.  
  398.             int nSnapMode = 0;
  399.             if (this.comboBoxSnapMode.SelectedIndex>=0)
  400.             {
  401.                 nSnapMode = m_dicSnapMode[this.comboBoxSnapMode.Text.ToString()];// m_stuSnapCfg[nChn].bTimingEnable > 0 ? 0 : 1;
  402.             }
  403.            
  404.            
  405.             if(m_bJSON == false)
  406.             {
  407.                 InitSnapConfigUI(nChn, e==null?false:true);
  408.                 UpdateSnapConfig(nChn, nSnapMode,  e);
  409.             }
  410.             else
  411.             {
  412.                 InitSnapConfigExUI(nChn);
  413.                 UpdateSnapConfig(nChn, nSnapMode,  e);
  414.             }
  415.         }
  416.  
  417.         private void OnSelchangeComboSnapMode(object sender, EventArgs e)
  418.         {
  419.             int nSnapMode = 0;
  420.             int nIndex = this.comboBoxSnapMode.SelectedIndex;// m_ccbSnapMode.GetCurSel();
  421.             if (nIndex >= 0)
  422.             {
  423.                 m_snapmode = m_dicSnapMode[this.comboBoxSnapMode.Text.ToString()];
  424.                 if (m_snapmode == 1)
  425.                 {
  426.                     m_stuSnapCfg[ushort.Parse(this.comboBoxChannel.Text.ToString())].bTimingEnable = 1;
  427.                 }
  428.                 else
  429.                 {
  430.                     m_stuSnapCfg[ushort.Parse(this.comboBoxChannel.Text.ToString())].bTimingEnable = 0;
  431.                 }
  432.  
  433.                 OnSelchangeComboChannel(null,null);
  434.             }
  435.         }
  436.  
  437.         private void OnSelchangeComboSnapSize(object sender, EventArgs e)
  438.         {
  439.             int nSnapMode = 0;
  440.             int nIndex = this.comboBoxSnapMode.SelectedIndex;
  441.             if (nIndex >= 0)
  442.             {
  443.                 nSnapMode = m_dicSnapMode[this.comboBoxSnapMode.Text.ToString()];
  444.  
  445.                 nIndex = this.comboBoxRe.SelectedIndex;
  446.                 if (nIndex >= 0)
  447.                 {
  448.                     int nIndexChl = this.comboBoxChannel.SelectedIndex;
  449.                     if (nIndexChl < 0)
  450.                     {
  451.                         return;
  452.                     }
  453.                     int nChl = nIndexChl;
  454.                     m_stuSnapCfg[nChl].struSnapEnc[nSnapMode].byImageSize = (byte)m_dicPix[this.comboBoxRe.Text.ToString()];//m_ccbSize.GetItemData(nIndex);
  455.                 }
  456.             }
  457.         }
  458.  
  459.         private void OnSelchangeComboSnapSpace(object sender, EventArgs e)
  460.         {
  461.             int nSnapMode = 0;
  462.             int nIndex = this.comboBoxSnapMode.SelectedIndex;
  463.             if (nIndex >= 0)
  464.             {
  465.                 nSnapMode = m_dicSnapMode[this.comboBoxSnapMode.Text.ToString()];
  466.  
  467.                 nIndex = this.comboBoxSnapSpace.SelectedIndex;
  468.                 if (nIndex >= 0)
  469.                 {
  470.                     int nIndexChl = this.comboBoxChannel.SelectedIndex;
  471.                     if (nIndexChl < 0)
  472.                     {
  473.                         return;
  474.                     }
  475.                     int nChl = nIndexChl;
  476.                     m_stuSnapCfg[nChl].struSnapEnc[nSnapMode].byFramesPerSec = (byte)m_dicSnapSpace[this.comboBoxSnapSpace.Text.ToString()];//m_ccbFrameRate.GetItemData(nIndex);
  477.                 }
  478.             }
  479.         }
  480.  
  481.         private void OnSelchangeComboSnapQuality(object sender, EventArgs e)
  482.         {
  483.             int nSnapMode = 0;
  484.             int nIndex = this.comboBoxSnapMode.SelectedIndex;
  485.             if (nIndex >= 0)
  486.             {
  487.                 nSnapMode = m_dicSnapMode[this.comboBoxSnapMode.Text.ToString()];
  488.  
  489.                 nIndex = this.comboBoxQuality.SelectedIndex;
  490.                 if (nIndex >= 0)
  491.                 {
  492.                     int nIndexChl = this.comboBoxChannel.SelectedIndex;
  493.                     if (nIndex < 0)
  494.                     {
  495.                         return;
  496.                     }
  497.                     int nChl = nIndexChl;
  498.                     m_stuSnapCfg[nChl].struSnapEnc[nSnapMode].byImageQlty = (byte)m_dicQuality[this.comboBoxQuality.Text.ToString()];//m_ccbQuality.GetItemData(nIndex);
  499.                 }
  500.             }  
  501.         }
  502.  
  503.         private void OnCheckTimeEnable(object sender, EventArgs e)
  504.         {
  505.             m_bEnable = !m_bEnable;
  506.             int nSnapMode = 0;
  507.             int nIndex = this.comboBoxSnapMode.SelectedIndex;
  508.             if (nIndex >= 0)
  509.             {
  510.                 nSnapMode = m_dicSnapMode[this.comboBoxSnapMode.Text.ToString()];
  511.                 if (nSnapMode != 0)
  512.                 {
  513.                     return;
  514.                 }
  515.  
  516.                 nIndex = this.comboBoxChannel.SelectedIndex;
  517.                 if (nIndex < 0)
  518.                 {
  519.                     return;
  520.                 }
  521.                 int nChl = nIndex;
  522.  
  523.                 m_stuSnapCfg[nChl].bTimingEnable = (byte)(m_bEnable==true?1:0);
  524.                 m_stuSnapCfg[nChl].struSnapEnc[0].byAudioEnable = (byte)(m_bEnable == true ? 1 : 0);
  525.                 m_stuSnapCfg[nChl].struSnapEnc[0].byVideoEnable = (byte)(m_bEnable == true ? 1 : 0);
  526.                 m_stuSnapCfg[nChl].struSnapEnc[1].byAudioEnable = (byte)(m_bEnable == true ? 1 : 0);
  527.                 m_stuSnapCfg[nChl].struSnapEnc[1].byVideoEnable = (byte)(m_bEnable == true ? 1 : 0);
  528.             }
  529.         }
  530.  
  531.         private void InitSnapConfigUI(int nChn, bool bInitSnapmode)
  532.         {
  533.             //const DH_QUERY_SNAP_INFO& stuSnapInfo = m_stuSnapAttr.stuSnap[nChn];
  534.            
  535.  
  536.             if (bInitSnapmode)
  537.             {
  538.                 this.comboBoxSnapMode.Items.Clear();
  539.                 for (int i = 0; i < m_stuSnapAttr.stuSnap[nChn].nSnapModeCount; i++)
  540.                 {
  541.                     if (m_stuSnapAttr.stuSnap[nChn].SnapMode[i] == 0)
  542.                     {
  543.                         this.comboBoxSnapMode.Items.Add("定时触发抓图");
  544.                         m_dicSnapMode["定时触发抓图"] = 0;
  545.                     }
  546.                     else if (m_stuSnapAttr.stuSnap[nChn].SnapMode[i] == 1)
  547.                     {
  548.                         this.comboBoxSnapMode.Items.Add("手动触发抓图");
  549.                         m_dicSnapMode["手动触发抓图"] = 1;
  550.                     }
  551.                 }
  552.             }
  553.            
  554.  
  555.             this.comboBoxSnapSpace.Items.Clear();
  556.             string csFrame = "";
  557.             for(int i = 0; i < m_stuSnapAttr.stuSnap[nChn].nFramesCount; i++)
  558.             {
  559.                 if(m_stuSnapAttr.stuSnap[nChn].Frames[i] > 0)
  560.                 {
  561.                     csFrame = string.Format("{0:n0} 秒1帧", m_stuSnapAttr.stuSnap[nChn].Frames[i]);
  562.                 }
  563.                 else if(m_stuSnapAttr.stuSnap[nChn].Frames[i] < 0)
  564.                 {
  565.                     csFrame = string.Format("{0:n0} 秒1帧", Math.Abs(m_stuSnapAttr.stuSnap[nChn].Frames[i]));
  566.                 }
  567.                 this.comboBoxSnapSpace.Items.Add(csFrame);
  568.                 m_dicSnapSpace[csFrame] = m_stuSnapAttr.stuSnap[nChn].Frames[i];
  569.             }
  570.  
  571.  
  572.             UInt32 dwMask = 0x0001;
  573.             this.comboBoxRe.Items.Clear();
  574.             for (int i = 0; i < 32; i++)
  575.             {
  576.                 if ((m_stuSnapAttr.stuSnap[nChn].dwVideoStandardMask & dwMask) > 0)
  577.                 {
  578.                     foreach (KeyValuePair<string,int> temp in m_dicPix)
  579.                     {
  580.                         if (temp.Value == i)
  581.                         {
  582.                             this.comboBoxRe.Items.Add(temp.Key);
  583.                         }
  584.                     }
  585.                 }
  586.                 dwMask <<= 1;
  587.             }
  588.            
  589.             string csQuality;
  590.             //m_ccbQuality.ResetContent();
  591.             this.comboBoxQuality.Items.Clear();
  592.             for(int i = 0; i < m_stuSnapAttr.stuSnap[nChn].nPicQualityCount; i++)
  593.             {
  594.                 csQuality = string.Format("{0:n0}%", m_stuSnapAttr.stuSnap[nChn].PictureQuality[i]);
  595.                 this.comboBoxQuality.Items.Add(csQuality);
  596.                 m_dicQuality[csQuality] = m_stuSnapAttr.stuSnap[nChn].PictureQuality[i];
  597.             }
  598.         }
  599.  
  600.         private void UpdateSnapConfig(int nChn, int nSnapMode, EventArgs e)
  601.         {
  602.             if(nChn < 0 || nChn > 32 || nSnapMode < 0 || nSnapMode > 1)
  603.             {
  604.                 return;
  605.             }
  606.            
  607.            
  608.             int nCount = 0;
  609.             if (e!=null)
  610.             {
  611.                  nCount = this.comboBoxSnapMode.Items.Count;// m_ccbSnapMode.GetCount();
  612.                 if (nCount > 0 && nCount >= nSnapMode)
  613.                 {
  614.                     for (int i = 0; i < nCount; i++)
  615.                     {
  616.                         if (i == nSnapMode)
  617.                         {
  618.                             this.comboBoxSnapMode.SelectedIndex = i;
  619.                             break;
  620.                         }
  621.                     }
  622.                 }
  623.             }
  624.            
  625.            
  626.  
  627.             nCount = this.comboBoxSnapSpace.Items.Count;// m_ccbFrameRate.GetCount();
  628.             foreach (KeyValuePair<string,int> temp in m_dicSnapSpace)
  629.             {
  630.                 if (temp.Value == (sbyte)m_stuSnapCfg[nChn].struSnapEnc[nSnapMode].byFramesPerSec)
  631.                 {
  632.                     this.comboBoxSnapSpace.SelectedIndex = this.comboBoxSnapSpace.FindString(temp.Key);
  633.                     break;
  634.                 }
  635.                 if (Math.Abs(m_stuSnapCfg[nChn].struSnapEnc[nSnapMode].byFramesPerSec) == Math.Abs(temp.Value))
  636.                 {
  637.                     this.comboBoxSnapSpace.SelectedIndex = this.comboBoxSnapSpace.FindString(temp.Key);
  638.                     break;
  639.                 }
  640.             }
  641.  
  642.             foreach (KeyValuePair<string, int> temp in m_dicPix)
  643.             {
  644.                 if (temp.Value == m_stuSnapCfg[nChn].struSnapEnc[nSnapMode].byImageSize)
  645.                 {
  646.                     this.comboBoxRe.SelectedIndex = this.comboBoxRe.FindString(temp.Key);
  647.                     break;
  648.                 }
  649.             }
  650.  
  651.             foreach (KeyValuePair<string, int> temp in m_dicQuality)
  652.             {
  653.                 if (temp.Value == m_stuSnapCfg[nChn].struSnapEnc[nSnapMode].byImageQlty)
  654.                 {
  655.                     this.comboBoxQuality.SelectedIndex = this.comboBoxQuality.FindString(temp.Key);
  656.                     break;
  657.                 }
  658.             }
  659.         }
  660.            
  661.         private void  InitSnapConfigExUI(int nChn)
  662.         {
  663.              if(m_stuSnapAttrEx.m_bQueried[nChn] == 0)
  664.              {
  665.                  object result = new object();
  666.                  UInt32 dwRetLen = 0;
  667.                  bool bRet = bRet = DHClient.DHGetNewDevConfig(m_nLoginID, 0,
  668.                      DHClient.CFG_CMD_SNAPCAPINFO, ref result, typeof(CFG_SNAPCAPINFO_INFO), 0, 3000);
  669.                  if(bRet == false)
  670.                  {
  671.                     // MessageBox.Show("获取设备能力集失败");
  672.                    
  673.                     return;
  674.                  }
  675.  
  676.                  m_stuSnapAttrEx.m_stuSnapAttrEx[nChn] = (CFG_SNAPCAPINFO_INFO)result;
  677.                  m_stuSnapAttrEx.m_bQueried[nChn] = 1;
  678.              }
  679.  
  680.              if(m_stuSnapAttrEx.m_bQueried[nChn] == 0)
  681.              {
  682.                  return;
  683.              }
  684.              
  685.               CFG_SNAPCAPINFO_INFO  stuSnapInfo = m_stuSnapAttrEx.m_stuSnapAttrEx[nChn];
  686.               int i = 0;
  687.  
  688.               this.comboBoxSnapMode.Items.Clear();
  689.               if((stuSnapInfo.dwMode&0x00000001) > 0)
  690.               {
  691.                   this.comboBoxSnapMode.Items.Add("定时触发抓图");
  692.                   m_dicPix["定时触发抓图"] = 0;
  693.               }
  694.               if((stuSnapInfo.dwMode&0x00000002) > 0)
  695.               {
  696.                   this.comboBoxSnapMode.Items.Add("手动触发抓图");
  697.                   m_dicPix["手动触发抓图"] = 1;
  698.               }
  699.  
  700.              //
  701.               string csFrame = "";
  702.               this.comboBoxSnapSpace.Items.Clear();
  703.               for(i = 0; i < stuSnapInfo.dwFramesPerSecNum; i++)
  704.               {
  705.                   if(stuSnapInfo.nFramesPerSecList[i] > 0)
  706.                   {
  707.                       csFrame = string.Format("{0:n0} 秒1帧", stuSnapInfo.nFramesPerSecList[i]);
  708.                   }
  709.                   else if(stuSnapInfo.nFramesPerSecList[i] < 0)
  710.                   {
  711.                       csFrame = string.Format("{0:n0} 秒1帧", Math.Abs(stuSnapInfo.nFramesPerSecList[i]));
  712.                   }
  713.                   m_dicSnapSpace[csFrame] = stuSnapInfo.nFramesPerSecList[i];
  714.               }
  715.           //
  716.           //        IMAGE_SIZE_D1,                              // 704*576(PAL)  704*480(NTSC)
  717.           //        IMAGE_SIZE_HD1,                             // 352*576(PAL)  352*480(NTSC)
  718.           //        IMAGE_SIZE_BCIF,                            // 704*288(PAL)  704*240(NTSC)
  719.           //        IMAGE_SIZE_CIF,                             // 352*288(PAL)  352*240(NTSC)
  720.           //        IMAGE_SIZE_QCIF,                            // 176*144(PAL)  176*120(NTSC)
  721.           //        IMAGE_SIZE_VGA,                             // 640*480
  722.           //        IMAGE_SIZE_QVGA,                            // 320*240
  723.           //        IMAGE_SIZE_SVCD,                            // 480*480
  724.           //        IMAGE_SIZE_QQVGA,                           // 160*128
  725.           //        IMAGE_SIZE_SVGA,                            // 800*592
  726.           //        IMAGE_SIZE_XVGA,                            // 1024*768
  727.           //        IMAGE_SIZE_WXGA,                            // 1280*800
  728.           //        IMAGE_SIZE_SXGA,                            // 1280*1024  
  729.           //        IMAGE_SIZE_WSXGA,                           // 1600*1024  
  730.           //        IMAGE_SIZE_UXGA,                            // 1600*1200
  731.           //        IMAGE_SIZE_WUXGA,                           // 1920*1200
  732.           //        IMAGE_SIZE_LTF,                             // 240*192
  733.           //        IMAGE_SIZE_720,                             // 1280*720
  734.           //        IMAGE_SIZE_1080,                            // 1920*1080
  735.           //        IMAGE_SIZE_1_3M,                            // 1280*960
  736.           //        IMAGE_SIZE_NR  
  737.  
  738.               //
  739.               UInt32 dwMask = 0x0001;
  740.               this.comboBoxRe.Items.Clear();
  741.               for (i = 0; i < 32; i++)
  742.               {
  743.                   if ((m_stuSnapAttr.stuSnap[nChn].dwVideoStandardMask & dwMask) > 0)
  744.                   {
  745.                       foreach (KeyValuePair<string, int> temp in m_dicPix)
  746.                       {
  747.                           if (temp.Value == i)
  748.                           {
  749.                               this.comboBoxRe.Items.Add(temp.Key);
  750.                           }
  751.                       }
  752.                   }
  753.                   dwMask <<= 1;
  754.               }
  755.              
  756.               //
  757.               //IMAGE_QUALITY_Q10 = 1,                          // 图像质量10%
  758.               //IMAGE_QUALITY_Q30,                              // 图像质量30%
  759.               //IMAGE_QUALITY_Q50,                              // 图像质量50%
  760.               //IMAGE_QUALITY_Q60,                              // 图像质量60%
  761.               //IMAGE_QUALITY_Q80,                              // 图像质量80%
  762.               //IMAGE_QUALITY_Q100,                             // 图像质量100%
  763.                int[] nMapQuality = {0, 10, 30, 50, 60, 80, 100};
  764.               string csQuality = "";
  765.               this.comboBoxQuality.Items.Clear();
  766.               for(i = 0; i < stuSnapInfo.dwQualityMun; i++)
  767.               {
  768.                   if (stuSnapInfo.emQualityList[i] > 0 && (int)(stuSnapInfo.emQualityList[i]) < 7)
  769.                   {
  770.                       csQuality = string.Format("{0:n0}%", nMapQuality[(int)(stuSnapInfo.emQualityList[i])]);
  771.                   }
  772.                  
  773.                   this.comboBoxQuality.Items.Add(csQuality);
  774.                   m_dicQuality[csQuality] = m_stuSnapAttr.stuSnap[nChn].PictureQuality[i];
  775.               }
  776.         }
  777.  
  778.         private void DisConnectEvent(int lLoginID, StringBuilder pchDVRIP, int nDVRPort, IntPtr dwUser)
  779.         {
  780.            // MessageBox.Show("设备断开!");
  781.         }
  782.  
  783.         private int m_nCountPic;//用户图片计数
  784.         private void SnapRev(Int32 lLoginID, IntPtr pBuf, UInt32 RevLen, UInt32 EncodeType, UInt32 CmdSerial, UInt32 dwUser)
  785.         {
  786.             CounterChannel = CounterChannel + 1;
  787.  
  788.             byte[] buf = new byte[RevLen];
  789.             Marshal.Copy(pBuf, buf, 0, (int)RevLen);
  790.  
  791.             string strName = string.Format(textBoxIP.Text+"_"+ textBoxPort.Text + "_"+textBoxUser.Text+"_"+ textBoxPsw.Text + "_"+"{0:n0}.jpg", m_nCountPic++);
  792.             // Create the file.
  793.             using (System.IO.FileStream fs = System.IO.File.Create(strName))
  794.             {
  795.                 //Marshal.read
  796.                 fs.Write(buf, 0, (int)RevLen);
  797.                 fs.Close();
  798.             if (CounterChannel == comboBoxChannel.Items.Count)
  799.             {
  800.                     Application.Exit();
  801.  
  802.                 }
  803.            
  804.             //  MessageBox.Show("获取的图片在本工作目录下,图片名为"+strName);
  805.             }
  806.                        
  807.             return ;
  808.         }
  809.  
  810.         private int m_nLoginID;     //登陆设备的ID
  811.         private bool m_bInit;       //库是否初始化成功
  812.         private int m_nChannelNum;  //设备的通道个数
  813.         private bool m_bJSON;       //
  814.         private bool m_bEnable;
  815.  
  816.         private int m_snapmode;
  817.  
  818.         private Dictionary<string, int> m_dicPix;//分辨率
  819.         private Dictionary<string, int> m_dicQuality;//图像质量
  820.         private Dictionary<string, int> m_dicSnapSpace;//抓图间隔
  821.         private Dictionary<string, int> m_dicSnapMode;//抓图模式
  822.  
  823.         private DH_SNAP_ATTR_EN m_stuSnapAttr;
  824.         private DH_SNAP_ATTR_EN_EX m_stuSnapAttrEx;
  825.  
  826.         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
  827.         private DHDEV_SNAP_CFG[] m_stuSnapCfg;
  828.  
  829.         // 委托
  830.         private fDisConnect m_disConnect;
  831.         private fSnapRev m_SnapRecv;
  832.  
  833.         public int CounterChannel { get; private set; }
  834.  
  835.         public struct DH_SNAP_ATTR_EN_EX
  836.         {
  837.             [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
  838.             public Int32[] m_bQueried;
  839.             [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
  840.             public CFG_SNAPCAPINFO_INFO[]   m_stuSnapAttrEx;
  841.         };
  842.  
  843.         private void textBoxIP_TextChanged(object sender, EventArgs e)
  844.         {
  845.  
  846.         }
  847.  
  848.         private void Form1_Load(object sender, EventArgs e)
  849.         {
  850.  
  851.         }
  852.     }
  853.  
  854. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement