封装了XnetSDK打开和镜像网络摄像头
By
admin
at 2023-10-10 • 0人收藏 • 1462人看过
之前那个X64网络摄线头帖子里只是实现了打开操作, 经过一天的研究才终于弄懂了怎么用json来配置这个网络摄像头,
下面是 NetSDKEx.dll的类库源码:
using System; using System.Collections.Generic; using System.Linq; using System.Net.Configuration; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using User.XNetSDK; using XSDK_HANDLE = System.Int32; namespace NetSDKEx { public class Video { XSDK_HANDLE hLoginID; XSDK_HANDLE hPlayer; public bool Open( string iPaddrss , IntPtr PicHandle) { SXSDKInitParam InitParam = new SXSDKInitParam(); XNetSDK.XSDK_Init(ref InitParam); SXSDKLoginParam LoginInfo = new SXSDKLoginParam(); LoginInfo.sDevId = iPaddrss; //IP addrss LoginInfo.sUserName = "admin"; //User name LoginInfo.sPassword = ""; //Password LoginInfo.nDevPort = 34567; //Port LoginInfo.nCnnType = EDEV_CNN_TYPE.EDEV_CNN_TYPE_AUTO; hLoginID = XNetSDK.XSDK_DevLoginSyn(ref LoginInfo, 500); if (hLoginID > 0) { SXMediaRealPlayReq param = new SXMediaRealPlayReq(); param.nChannel = 0; // Channel (required) param.nStreamType = 0; // Stream type (required) param.nRequestType = (int)EXSDK_DATA_FORMATE.EXSDK_DATA_FORMATE_FRAME; // Data type param.hShowWindows = PicHandle; // Window handle param.nDecodeType = (int)EXNetSDK_EDECODE_RESULT.DECODE_RESULT_NULL; hPlayer = XNetSDK.XSDK_MediaRealPlay(hLoginID, ref param, 0, 0); return true; } else { return false; } } public void FlipMirror(int flag) { if (hLoginID > 0) { IntPtr szOutBuffer = Marshal.AllocHGlobal(40960); int nInOutSize = 40960; XNetSDK.XSDK_DevGetChnConfigSyn(hLoginID, 0, "Camera.Param", szOutBuffer, ref nInOutSize, 4000, 1042); string result = Marshal.PtrToStringAnsi(szOutBuffer); switch (flag) { case 0://none result = result.Replace(" \"PictureFlip\" : \"0x00000001\"", " \"PictureFlip\" : \"0x00000000\""); result = result.Replace(" \"PictureMirror\" : \"0x00000001\"", " \"PictureMirror\" : \"0x00000000\""); break; case -1: case 1://mirror result = result.Replace(" \"PictureFlip\" : \"0x00000001\"", " \"PictureFlip\" : \"0x00000000\""); result = result.Replace(" \"PictureMirror\" : \"0x00000000\"", " \"PictureMirror\" : \"0x00000001\""); break; case -2: case 2://flip result = result.Replace(" \"PictureFlip\" : \"0x00000000\"", " \"PictureFlip\" : \"0x00000001\""); result = result.Replace(" \"PictureMirror\" : \"0x00000001\"", " \"PictureMirror\" : \"0x00000000\""); break; case -3: case 3://all result = result.Replace(" \"PictureFlip\" : \"0x00000000\"", " \"PictureFlip\" : \"0x00000001\""); result = result.Replace(" \"PictureMirror\" : \"0x00000000\"", " \"PictureMirror\" : \"0x00000001\""); break; default: break; } XNetSDK.XSDK_DevSetChnConfigSyn(hLoginID, 0, "Camera.Param", Encoding.Default.GetBytes(result), nInOutSize, szOutBuffer, ref nInOutSize, 4000, 1040); Marshal.FreeHGlobal(szOutBuffer); } } public void Close() { if (hPlayer > 0) { XNetSDK.XSDK_MediaStop(hPlayer); } if (hLoginID > 0) { XNetSDK.XSDK_DevLogout(hLoginID); } XNetSDK.XSDK_UnInit(); } } }
c#调用示例如下:
using NetSDKEx; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Video video1; int flag = 0; private void button1_Click(object sender, EventArgs e) { switch (flag) { case 0: flag= 1; break; case 1: flag = 3; break; case 2: flag = 0; break; case 3: flag = 2; break; default: break; } video1.FlipMirror(flag); } private void Form1_Load(object sender, EventArgs e) { video1 = new NetSDKEx.Video(); video1.Open("192.168.1.153", pictureBox1.Handle); } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { //video1.Close(); } } }
NetSDKEx.dll 类库生成工程下载:
示例工程下载:
链接:https://pan.baidu.com/s/1fFVQiL68pMZ-gdA-21J9eg?pwd=49ce
提取码:49ce
项目需要, 将这个摄像头类库也升级到了.net8.0版本
项目源码:
编译好的支持.net8.0的 NetSDKEx.dll 类库
用法和之前一样.
9 个回复 | 最后更新于 2024-07-09
封装了 拍照和录像 的功能
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net.Configuration; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using User.XNetSDK; using User.XPlaySDK; using XSDK_HANDLE = System.Int32; namespace NetSDKEx { public class Video { public XNetSDK.PXSDK_MessageCallBack _playCallback; public XSDK_HANDLE hDevice = 0; // Login handle public XSDK_HANDLE _hLoginID = 0; // Login handle public XSDK_HANDLE _hPlayer = 0; // Video handle public XSDK_HANDLE _xPlayer = 0; // Play handle public bool Open( string iPaddrss , IntPtr PicHandle) { SXSDKInitParam InitParam = new SXSDKInitParam(); XNetSDK.XSDK_Init(ref InitParam); SXSDKLoginParam LoginInfo = new SXSDKLoginParam(); LoginInfo.sDevId = iPaddrss; //IP addrss LoginInfo.sUserName = "admin"; //User name LoginInfo.sPassword = ""; //Password LoginInfo.nDevPort = 34567; //Port LoginInfo.nCnnType = EDEV_CNN_TYPE.EDEV_CNN_TYPE_AUTO; _hLoginID = XNetSDK.XSDK_DevLoginSyn(ref LoginInfo, 1000); if (_hLoginID > 0) { if (_hPlayer > 0) { XNetSDK.XSDK_MediaStop(_hPlayer); } SXMediaRealPlayReq param = new SXMediaRealPlayReq(); param.nChannel = 0; // Channel (required) param.nStreamType = 0; // Stream type (required) param.nRequestType = (int)EXSDK_DATA_FORMATE.EXSDK_DATA_FORMATE_NONE; // Data type param.hShowWindows = PicHandle; // Window handle param.nDecodeType = (int)EXNetSDK_EDECODE_RESULT.DECODE_RESULT_NULL; _hPlayer = XNetSDK.XSDK_MediaRealPlay(_hLoginID, ref param, 0, 0); _xPlayer = XNetSDK.XSDK_GetPlayHandle(_hPlayer); return true; } else { return false; } } public bool StartRecord(string path) { if (_hPlayer <= 0) { return false; } int m_bRecord = XPlaySDK.XPLAY_StartRecordData(_xPlayer, path); if (m_bRecord < 0) { return false; } return true; } public void StopRecord() { if (_hPlayer <= 0) { return; } if (_xPlayer>0) { XPlaySDK.XPLAY_StopRecordData(_xPlayer); } } public bool CatchPicture(string path) { if (_hPlayer <= 0) { return false; } int bCatch = XPlaySDK.XPLAY_CatchPicture(_xPlayer, path); if (bCatch < 0) { return false; } return true; } } }
登录后方可回帖
大佬你好,因为我的版本是4.6.0,用不了这个dll,请问大佬该怎么修改