封装了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();
        }
    }
}

screenshots.gif



NetSDKEx.dll 类库生成工程下载:

Xnet64.zip

示例工程下载:

链接:https://pan.baidu.com/s/1fFVQiL68pMZ-gdA-21J9eg?pwd=49ce 

提取码:49ce



项目需要, 将这个摄像头类库也升级到了.net8.0版本

项目源码: 

Xnet64-net8.zip

编译好的支持.net8.0的 NetSDKEx.dll 类库

NetSDKEx-net8.0-dll.zip

用法和之前一样.

9 个回复 | 最后更新于 2024-07-09
2023-12-22   #1

大佬你好,因为我的版本是4.6.0,用不了这个dll,请问大佬该怎么修改

2023-12-22   #2

回复#1 @q302543510 :

自己用vs改下net框架重新编译就行了

2023-12-22   #3

回复#2 @admin :

大佬还有最后一个问题,请指教image.png

2023-12-23   #4

回复#3 @q302543510 :

意思是没找到那个dll,把这个dll放入到你的debug或者release目录里就行了

2024-01-06   #5

请问大佬这里面有录制视频的代码吗

2024-01-10   #6

回复#5 @q302543510 :

sdk里有视频录像和播放功能, 我上面没封装, 你可以看他们官方的sdk demo示例

https://developer.jftech.com/docs/?menusId=57e91028bdc14909b269ddb19180d30a&siderid=2fff460ae8a448268137094ded532f67&lang=zh


2024-01-18   #7

项目需要, 同时将这个也升级到了net8.0 版本. 在楼顶已更新.

2024-07-03   #8

封装了 拍照和录像 的功能

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;
        }
    }
}

NetSDKEx.zip


2024-07-09   #9

啥用途捏

登录后方可回帖

登 录
信息栏
 私人小站

本站域名

ChengXu.XYZ

投诉联系:  popdes@126.com



快速上位机开发学习,本站主要记录了学习过程中遇到的问题和解决办法及上位机代码分享

这里主要专注于学习交流和经验分享.
纯私人站,当笔记本用的,学到哪写到哪.
如果侵权,联系 Popdes@126.com

友情链接
Aardio官方
Aardio资源网


才仁机械


网站地图SiteMap

Loading...