欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實(shí)現(xiàn)IP攝像頭的方法

 更新時(shí)間:2015年04月25日 15:33:03   作者:work24  
這篇文章主要介紹了C#實(shí)現(xiàn)IP攝像頭的方法,涉及C#IP連接與攝像頭視頻錄像的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了C#實(shí)現(xiàn)IP攝像頭的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

#region IP攝像頭代碼
/// <summary>
/// ip攝像頭代碼
/// </summary>  
//視頻
private IntPtr m_hChannel;
private IntPtr m_hServer, phPlay;
public delegate void MyInvoke(string str);
public delegate void OutDelegate(IntPtr hSearch, DVSNET_FILE_TIME pFileTime, DVSNET_FILE_INFO pFileInfo, IntPtr pcontext);
//遠(yuǎn)程視頻處理
public void BeforeRecordFrame(IntPtr hChannel, ref RECORD_INFO pRecordInfo, ref FRAME_HEADER pFrameHeader, IntPtr pcontext)
{
}
DVSNETClient.FileSearchCallback File_SearchCallback; //遠(yuǎn)程視頻回放
public void FileSearchCallback(IntPtr hSearch, ref DVSNET_FILE_TIME pFileTime, ref DVSNET_FILE_INFO pFileInfo, IntPtr pcontext)
{
OutText(hSearch, pFileTime, pFileInfo, pcontext);   
}
public void OutText(IntPtr hSearch, DVSNET_FILE_TIME pFileTime, DVSNET_FILE_INFO pFileInfo, IntPtr pcontext)
{
  if (lvVideo.InvokeRequired)
  {
   OutDelegate outdelegate = new OutDelegate(OutText);
   this.BeginInvoke(outdelegate, new object[] { hSearch, pFileTime, pFileInfo, pcontext });
   return;
  }
  lvVideo.View = View.Details;
  lvVideo.FullRowSelect = true;
  for (int i = 0; i < pFileInfo.sFileName.Count(); i++)
  {
   ListViewItem item1 = new ListViewItem(pFileInfo.sFileName, i);
   lvVideo.Items.AddRange(new ListViewItem[] { item1 });
  }
 }
 private void pb_del_video_Click(object sender, EventArgs e)
 {
  this.Close();
 }
 public void SearchNotify(int nDevType,string sServName,string sServSerial,string sUrl,IntPtr MacAddr,ushort wWebPort,ushort wDataPort,string sSubNetMask,string sGateWay,string sMultiIp,string sDNS,ushort wMultiPort,int nChCount,uint bDHCP,IntPtr pcontext)
 {
  string str = Convert.ToString(wDataPort);
  //string str2 = sUrl + "(" + str + ")";
  string str2 = sUrl;
  this.AddText(str2);
 }
 //賦值給cmbIP
 private void AddText(string str)
 {
  MyInvoke method = new MyInvoke(this.AddTextToCmb);
  base.BeginInvoke(method, new object[] { str });
 }
 public void AddTextToCmb(string str)
 {
  this.CmbIP.Items.Add(str);
 }
 //s搜索服務(wù)器
 private void btnVideoSearck_Click(object sender, EventArgs e)
 {
  
   this.CmbIP.Items.Clear();
   errornum errornum = DVSNETClient.DVSNET_SearchServers(0xbb8, 1, new DVSNETClient.SearchNotify(this.SearchNotify), base.Handle, IntPtr.Zero);
   if (errornum == errornum.DVSNET_ERR_OK)
   {
    timerVideo.Enabled = true;
    btnVideoSearck.Enabled = false;
   }
   else
   {
   }
 }
 //打開鏈接
 private void btnVideoOpen_Click(object sender, EventArgs e)
 {
  string text = this.CmbIP.Text;
  string sServIp = text;
  int index = text.IndexOf('(');
  if (index != -1)
  {
   string str3 = new string(text.ToCharArray(), 0, index);
   sServIp = str3;
  }
  errornum errornum = DVSNETClient.DVSNET_OpenServer(this.EdtName.Text, sServIp, Convert.ToUInt16(this.EdtPort.Text), this.EdtUser.Text, this.EdtPassword.Text, ref this.m_hServer, 0, 0);
  this.btnVideoOpen.Enabled = false; //不能點(diǎn)擊
  if (errornum == errornum.DVSNET_ERR_OK)
  {
   DVSNET_SERVER_INFO dvsnet_server_info = new DVSNET_SERVER_INFO();
   MessageBox.Show("打開鏈接成功!");
   dvsnet_server_info = new DVSNET_SERVER_INFO
   {
    lStructSize = Marshal.SizeOf(dvsnet_server_info)
   };
   DVSNETClient.DVSNET_GetServerInfo(this.m_hServer, ref dvsnet_server_info);
   // this.CmbChannel.Items.Clear();
   for (int i = 0; i < dvsnet_server_info.nChnNum; i++)
   {
    int num3 = i + 1;
    // this.CmbChannel.Items.Add(num3.ToString());
   }
   // this.CmbChannel.SelectedIndex = 0;
  }
  else
  {
   MessageBox.Show("打開鏈接失敗,錯(cuò)誤碼為:" + errornum.ToString());
   this.btnVideoOpen.Enabled = true; //不能點(diǎn)擊
  }
 }
 //關(guān)閉鏈接
 private void btnVideoClose_Click(object sender, EventArgs e)
 {
  if (this.m_hChannel != IntPtr.Zero)
  {
   MessageBox.Show("請關(guān)閉通道!再關(guān)閉鏈接");
  }
  else
  {
   if (this.m_hServer != IntPtr.Zero)
   {
    DVSNETClient.DVSNET_CloseServer(this.m_hServer);
    this.m_hServer = IntPtr.Zero;
    this.btnVideoOpen.Enabled = true; //不能點(diǎn)擊
   }
  }
 }
 //打開通道
 IntPtr selServer = IntPtr.Zero;
 private void btnVideoOpenChnnel_Click(object sender, EventArgs e)
 {
  this.panelVideo.Visible = true;
  this.pannelVideoTwo.Visible = false;
  if (this.m_hServer != IntPtr.Zero)
  {
   this.btnVideoOpenChnnel.Enabled = false; //不能點(diǎn)擊
   DVSNET_CHANNEL_INFO dvsnet_channel_info = new DVSNET_CHANNEL_INFO();
   MessageBox.Show("打開通道成功!請稍候");
   dvsnet_channel_info = new DVSNET_CHANNEL_INFO
   {
    lStructSize = Marshal.SizeOf(dvsnet_channel_info),
    nProtocol = 0,
    hWndDisplay = this.panelVideo.Handle,
    bPlayStart = 1,
    dwStreamNo = 0
   };
   DVSNETClient.DVSNET_OpenChannel(this.m_hServer, Convert.ToUInt16(0), ref dvsnet_channel_info, ref this.m_hChannel);
  }
  else
  {
   MessageBox.Show("請打開鏈接!");
  }
 }
 //關(guān)閉通道
 private void btnVideoCloseChnnel_Click(object sender, EventArgs e)
 {
  if (this.m_hChannel != IntPtr.Zero)
  {
   DVSNETClient.DVSNET_CloseChannel(this.m_hChannel);
   MessageBox.Show("關(guān)閉通道成功!請稍候");
   this.m_hChannel = IntPtr.Zero;
   this.btnVideoOpenChnnel.Enabled = true; //不能點(diǎn)擊
  }
 }
 //開始錄像
 private void btnVideoOn_Click(object sender, EventArgs e)
 {
  try
  {
   string ss = DateTime.Now.ToString().Replace(":", "-").Replace(" ", "-").Replace("/", "-") + ".asf";  
   if (this.panelVideo.Visible == false)
   {
    MessageBox.Show("請切換到打開通道");
   }
   else
   {
    if (this.m_hChannel != IntPtr.Zero)
    {
     this.btnVideoOn.Enabled = false; //不能點(diǎn)擊
     //DVSNETClient.DVSNET_StartRecord(this.m_hChannel, 1, FILETYPE.FILETYPE_ASF, ss, new DVSNETClient.BeforeRecordFrame(this.BeforeRecordFrame), base.Handle);
     DVSNETClient.DVSNET_StartRecord(this.m_hChannel, 1, FILETYPE.FILETYPE_ASF, ss,Before_RecordFrame, base.Handle);
    }
    else
    {
     MessageBox.Show("請打開通道!");
    }
   }
  }
  catch (Exception ex)
  {
   MessageBox.Show(ex.ToString());
  }  
 }
 //停止錄像
 private void btnStopRec_Click(object sender, EventArgs e)
 {
  DVSNETClient.DVSNET_StopRecord(this.m_hChannel);
  MessageBox.Show("已停止錄像!");
  this.btnVideoOn.Enabled = true; //不能點(diǎn)擊
 }
 //打開本地視頻
 IntPtr phPlayer;
 private void btnsearch_Click(object sender, EventArgs e)
 {
  try
  {
   if (m_hServer != IntPtr.Zero)
   {
    string fName = "";
    OpenFileDialog openFileDialog = new OpenFileDialog();
    openFileDialog.InitialDirectory = Application.StartupPath;
    //注意這里寫路徑時(shí)要用c:\而不是c:
    openFileDialog.Filter = "文本文件|*.asf|所有文件|*.asf";
    openFileDialog.RestoreDirectory = true;
    openFileDialog.FilterIndex = 1;
    if (openFileDialog.ShowDialog() == DialogResult.OK)
    {
     this.panelVideo.Visible = false;
     this.pannelVideoTwo.Visible = true;
     this.btnsearch.Enabled = false;
     fName = openFileDialog.FileName;
     IntPtr hDisplayWnd = pannelVideoTwo.Handle;
     phPlayer = (IntPtr)0;
     DVSNETClient.DVSPLAYER_ReleaseInstance(phPlayer); //釋放
     DVSNETClient.DVSPLAYER_Stop(phPlayer); //釋放本地
     errornum aa = DVSNETClient.DVSPLAYER_CreateInstance(hDisplayWnd, ref phPlayer, 0);      
     aa = DVSNETClient.DVSPLAYER_OpenFile(phPlayer,ref fName, 1);
     DVSNETClient.DVSPLAYER_Start(phPlayer);
    }
    else
    {
     this.panelVideo.Visible = true;
     this.pannelVideoTwo.Visible = false;
    }
   }
   else
   {
    MessageBox.Show("請打開通道!");
   }
  }
  catch (Exception)
  {
   throw;
  }   
 }
 //停止視頻播放
 private void btnhf_Click(object sender, EventArgs e)
 {
  this.panelVideo.Visible = true;
  this.pannelVideoTwo.Visible = false;
  IntPtr phPlayer = (IntPtr)0;
  DVSNETClient.DVSPLAYER_Stop(phPlayer);
  MessageBox.Show("已停止回放錄像!");
  this.btnsearch.Enabled = true; ;  
 }
 //查找遠(yuǎn)程視頻
 private void btnSearchbyName_Click(object sender, EventArgs e)
 {
  if (m_hServer == IntPtr.Zero)
  {
   MessageBox.Show("請先打開鏈接登錄服務(wù)器!");
   return;
  }
  this.btnSearchbyName.Enabled = false;
  DVSNET_FILE_TIME pStartTime = new DVSNET_FILE_TIME();
  pStartTime.lYear = (uint)this.dateTimePicker1.Value.Year;
  pStartTime.lMonth = (uint)this.dateTimePicker1.Value.Month;
  pStartTime.lDay = (uint)this.dateTimePicker1.Value.Day;
  pStartTime.nHour = 0;
  pStartTime.nMinute = 0;
  DVSNET_FILE_TIME pEndTime = new DVSNET_FILE_TIME();
  pEndTime.lYear = (uint)this.dateTimePicker1.Value.Year;
  pEndTime.lMonth = (uint)this.dateTimePicker1.Value.Month;
  pEndTime.lDay = (uint)this.dateTimePicker1.Value.Day;
  pEndTime.nHour = 23;
  pEndTime.nMinute = 59;
  IntPtr phSearch = IntPtr.Zero;
  //if(){}
  errornum bak = DVSNETClient.DVSNET_ServerFindFile(m_hServer, 0, 0, (char)0xff, ref pStartTime, ref pEndTime, File_SearchCallback, (IntPtr)0, ref phSearch);
  if (bak != errornum.DVSNET_ERR_OK)
  {
   MessageBox.Show("查找遠(yuǎn)程視頻失??!");
  }   
  this.btnSearchbyName.Enabled = true;
 }
 //鼠標(biāo)雙擊事件
 private void lvVideo_MouseDoubleClick(object sender, MouseEventArgs e)
 {
  this.panelVideo.Visible = false;
  this.pannelVideoTwo.Visible = true;   
  string sa = "";
  IntPtr hWnd = pannelVideoTwo.Handle;
  if (lvVideo.SelectedItems.Count > 0)
  { //this.listView1.SelectedIndices
   sa = lvVideo.SelectedItems[0].Text.ToString();
  }
  
  DVSNETClient.DVSPLAYER_Stop(phPlayer); //釋放本地回放
  DVSNETClient.DVSNET_ClosePlayFile(phPlay); //釋放遠(yuǎn)程
  phPlay = IntPtr.Zero;
  errornum bak = DVSNETClient.DVSNET_PlayFileByName(m_hServer, sa, 1, hWnd, ref phPlay);
  if (bak == errornum.DVSNET_ERR_OK)
  {
   UInt32 value = 0;
   DVSNETClient.DVSNET_ControlPlayFile(phPlay, 1, 0, ref value);
  }
  else
  {
   MessageBox.Show("回放遠(yuǎn)程文件 失敗,錯(cuò)誤碼為" + bak.ToString());
  }
 }
 #endregion
 //時(shí)間控件 1s
 private void timerVideo_Tick(object sender, EventArgs e)
 {
  int nStatus = 0;
  errornum errnum = DVSNETClient.DVSNET_GetSearchStatus(ref nStatus);
  if (errnum == errornum.DVSNET_ERR_OK)
  {
   if (nStatus == 1)
   {
    btnVideoSearck.Enabled = true;
    timerVideo.Enabled = false;
    MessageBox.Show("沒有啟動(dòng)搜索");
   }
   if (nStatus == 2)
   {
    //MessageBox.Show("正在搜索!");
   }
   if (nStatus == 3)
   {
    timerVideo.Enabled = false;
    btnVideoSearck.Enabled = true;
    if (this.CmbIP.Items.Count == 0)
    {
     MessageBox.Show("沒有找到設(shè)備!請接上設(shè)備");
    }
    else
    {
     MessageBox.Show("已找到設(shè)備,請選擇IP地址");
    }
   }
  }
  else
  {
   MessageBox.Show("DVSNET_GetSearchStatus 失敗,錯(cuò)誤碼為" + errnum.ToString());
  }
}

希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • C#實(shí)現(xiàn)用戶自定義控件中嵌入自己的圖標(biāo)

    C#實(shí)現(xiàn)用戶自定義控件中嵌入自己的圖標(biāo)

    這篇文章主要介紹了C#實(shí)現(xiàn)用戶自定義控件中嵌入自己的圖標(biāo),較為詳細(xì)的分析了C#實(shí)現(xiàn)自定義控件中嵌入圖標(biāo)的具體步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-03-03
  • c# 正則指引--字符組

    c# 正則指引--字符組

    c#中通過正則來判斷數(shù)字字符在同一個(gè)位子可能出現(xiàn)的各種字符,需要的朋友可以參考下
    2012-10-10
  • C#更改tabControl選項(xiàng)卡顏色的方法

    C#更改tabControl選項(xiàng)卡顏色的方法

    這篇文章主要介紹了C#更改tabControl選項(xiàng)卡顏色的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了C#更改tabControl選項(xiàng)卡顏色的的具體步驟與相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2016-03-03
  • 詳解C#中的string與String

    詳解C#中的string與String

    本篇文章主要對jC#中的小寫string與大寫String進(jìn)行詳細(xì)介紹,相信對大家學(xué)習(xí)會有很好的幫助,需要的朋友一起來看下吧
    2016-12-12
  • C#10的13個(gè)特性

    C#10的13個(gè)特性

    本文詳細(xì)講解了C#10的13個(gè)特性,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-12-12
  • c#?定期重啟程序操作的實(shí)現(xiàn)

    c#?定期重啟程序操作的實(shí)現(xiàn)

    本文主要介紹了c#?定期重啟程序操作的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-09-09
  • 手動(dòng)編譯C#代碼的方法

    手動(dòng)編譯C#代碼的方法

    在本文里小編給大家分享的是關(guān)于手動(dòng)編譯C#代碼的方法和步驟,對此有需要的朋友們可以學(xué)習(xí)下。
    2018-12-12
  • C#中IEnumerable、ICollection、IList、List之間的區(qū)別

    C#中IEnumerable、ICollection、IList、List之間的區(qū)別

    IEnumerable、ICollection、IList、List之間的區(qū)別,本文分別分析了它的實(shí)現(xiàn)源碼,從而總結(jié)出了它們之間的關(guān)系和不同之處。對C# IEnumerable、ICollection、IList、List相關(guān)知識,感興趣的朋友一起看看吧
    2021-07-07
  • C#實(shí)現(xiàn)計(jì)算器功能

    C#實(shí)現(xiàn)計(jì)算器功能

    這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • 基于c# 接口的實(shí)例詳解

    基于c# 接口的實(shí)例詳解

    本篇文章是對c#中的接口進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06

最新評論