91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C#:使用海康SDK繪圖回調函數DrawFun()

發布時間:2020-07-14 21:34:57 來源:網絡 閱讀:2700 作者:006玩命 欄目:編程語言

簡述

??使用海康攝像頭采集圖像時,需要在圖像上添加圖標、文字等額外數據。可選擇使用SDK提供的NET_DVR_RigisterDrawFun()函數注冊繪圖回調函數,使用NET_DVR_RealPlay_V40()的返回值(用于在DrawFun()函數中區分通道數據)及DrawFun回調函數的指針進行注冊。注意:使用DrawFun回調函數,需要在調用NET_DVR_RealPlay_V40()時將第三個參數設置為null。

代碼

class DeviceCamera : IDeviceCamera
    {
        private CameraInfo m_stCameraInfo;

        private bool m_bInitSDK = false;
        private Int32 m_lUserID = -1;
        private Int32 m_lRealHandle = -1;

        private CHCNetSDK.DRAWFUN cbDrawFun = null;

        public override bool InitCamera( CameraInfo stInfo )
        {
            m_stCameraInfo = stInfo;

            //
            m_bInitSDK = CHCNetSDK.NET_DVR_Init();
            if ( m_bInitSDK == false )
            {
                uint nError = CHCNetSDK.NET_DVR_GetLastError();
                MessageBox.Show( "NET_DVR_Init error! ErrorCode: " + nError );
                return false;
            }
            else
                CHCNetSDK.NET_DVR_SetLogToFile( 3, "C:\\SdkLog\\", true );

            CHCNetSDK.NET_DVR_SetConnectTime( 5000, 1 );
            CHCNetSDK.NET_DVR_SetReconnect( 10000, 1 );

            string DVRIPAddress = stInfo.strIP;     
            Int16 DVRPortNumber = stInfo.nPort;     
            string DVRUserName = stInfo.strUserName;
            string DVRPassword = stInfo.strPassword;
            CHCNetSDK.NET_DVR_DEVICEINFO_V30 DeviceInfo = new CHCNetSDK.NET_DVR_DEVICEINFO_V30();
            m_lUserID = CHCNetSDK.NET_DVR_Login_V30( DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo );
            if ( m_lUserID < 0 )
            {
                MessageBox.Show( "登錄失敗!" );
                CHCNetSDK.NET_DVR_Cleanup();
                return false;
            }

            //
            CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO() 
            {
                dwStreamType = 0,    
                dwLinkMode = 0,    
                bBlocked = true,     
                dwDisplayBufNum = 10,
            };

            //遍歷PictureBox列表
            cbDrawFun = new CHCNetSDK.DRAWFUN( fDrawFun );
            int nPicBoxSize = m_stCameraInfo.lstPicBoxHdc.Count() <= 4 ? m_stCameraInfo.lstPicBoxHdc.Count() : 4; //海康攝像頭模擬通道數 <= 4
            for ( int nPicBoxIndex = 1; nPicBoxIndex <= nPicBoxSize; nPicBoxIndex++ )
            {
                lpPreviewInfo.hPlayWnd = m_stCameraInfo.lstPicBoxHdc[ nPicBoxIndex - 1 ];
                lpPreviewInfo.lChannel = nPicBoxIndex;
                m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40( m_lUserID, ref lpPreviewInfo, null, new IntPtr() );

                //設置異常消息回調函數
                bool bRet = CHCNetSDK.NET_DVR_SetExceptionCallBack_V30( 0, lpPreviewInfo.hPlayWnd, new CHCNetSDK.EXCEPYIONCALLBACK( cbException ), new IntPtr() );
                if ( !bRet )
                    MessageBox.Show( "設置異常消息回調函數失敗!" );

                //注冊繪圖回調函數
                bRet = CHCNetSDK.NET_DVR_RigisterDrawFun( m_lRealHandle, cbDrawFun, 0 );
                if ( !bRet )
                {
                    MessageBox.Show( "注冊繪圖回調函數失敗!" );
                    return false;
                }
            }

            return true;
        }

        private void fDrawFun( int lRealHandle, IntPtr hDC, uint dwUser )
        {
            try
            {
                Graphics pDC = Graphics.FromHdc( hDC );
                if ( null == pDC )
                    return;
                Brush hBrush = new SolidBrush( Color.Red );
                Pen pen = new Pen( hBrush );

                Rectangle rectTmp = new Rectangle( 100, 100, 100, 100 ); 

               if( 0 == lRealHandle )//Channel 1
               {
                   //Image
                   Bitmap img = new Bitmap( "../Images/NucSource.png" );
                   pDC.DrawImage( img, rectTmp );

                   //Text
                   string strText = "Novel RPS";
                   Font font = new Font( "黑體", 18, FontStyle.Italic | FontStyle.Bold );
                   Point pt = new Point( 100, 75 );
                   pDC.DrawString( strText, font, hBrush, pt );

                   //Rectangle
                   pDC.DrawRectangle( pen, rectTmp );
                   img.Dispose();
               }
               else if ( 1 == lRealHandle )//Channel 2
               {
                   //Text
                   string strText = "Novel RPS";
                   Font font = new Font( "黑體", 18, FontStyle.Italic | FontStyle.Bold );
                   Point pt = new Point( 100, 75 );
                   pDC.DrawString( strText, font, hBrush, pt );
               }
               else if ( 2 == lRealHandle )//Channel 3
               {
                   //Rectangle
                   pDC.DrawRectangle( pen, rectTmp );
               }
               else if ( 3 == lRealHandle )//Channel 4
               {
                   //Image
                   Bitmap img = new Bitmap( "../Images/NucSource.png" );
                   pDC.DrawImage( img, rectTmp );
                   img.Dispose();
               }

               hBrush.Dispose();
               pen.Dispose();
               pDC.Dispose();
            }
            catch
            {
                uint nError = CHCNetSDK.NET_DVR_GetLastError();
                if( nError != 0 )
                    MessageBox.Show( "cbDrawFun -- Catch Error Code: " + nError );
            }
        }

        private void cbException( uint dwType, int lUserID, int lHandle, IntPtr pUser )
        {
            switch( dwType )
            {
                case 0x8000:
                    MessageBox.Show( "語音對講時網絡異常!" );
                    break;
                case 0x8002:
                    MessageBox.Show( "報警上傳時網絡異常!" );
                    break;
                case 0x8003:
                    MessageBox.Show( "網絡預覽時網絡異常!" );
                    break;
                case 0x8004:
                    MessageBox.Show( "透明通道傳輸時網絡異常!" );
                    break;
                case 0x8005:
                    MessageBox.Show( "預覽時重連!" );
                    break;
                default:
                    MessageBox.Show( "攝像頭默認異常!" );
                    break;
            }
        }
    }

注:代碼中使用PictureBox顯示攝像頭圖像,故將其句柄設置給 lpPreviewInfo.hPlayWnd。

效果示例

C#:使用海康SDK繪圖回調函數DrawFun()

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

永春县| 霍林郭勒市| 广安市| 嘉善县| 启东市| 临邑县| 高青县| 旅游| 阳山县| 西乌珠穆沁旗| 光山县| 佛学| 龙山县| 南汇区| 龙陵县| 抚宁县| 铜山县| 安徽省| 潢川县| 余干县| 嵊州市| 临海市| 泰州市| 乐业县| 名山县| 汉寿县| 高青县| 稷山县| 班戈县| 莒南县| 鹤岗市| 商南县| 临澧县| 南和县| 鄱阳县| 冀州市| 会同县| 高雄市| 舞钢市| 江达县| 屏东市|