C# 调用海康SDK 预览画面叠加字符和图像(NET_DVR_RigisterDrawFun)问题

无法进入回调函数DrawFunCallBack,

        public void RealDataCallBack(Int32 lRealHandle, UInt32 dwDataType, ref byte pBuffer, UInt32 dwBufSize, IntPtr pUser)
        {
            //MyDebugInfo AlarmInfo = new MyDebugInfo(DebugInfo);
            switch (dwDataType)
            {
                case CHCNetSDK.NET_DVR_SYSHEAD:     // sys head
                    if (!PlayCtrl.PlayM4_GetPort(ref m_lPort))
                    {
                        MessageBox.Show("Get Port Fail");
                    }

                    if (dwBufSize > 0)
                    {
                        //set as stream mode, real-time stream under preview
                        if (!PlayCtrl.PlayM4_SetStreamOpenMode(m_lPort, PlayCtrl.STREAME_REALTIME))
                        {
                            //this.BeginInvoke(AlarmInfo, "PlayM4_SetStreamOpenMode fail");
                        }

                        //start player
                        if (!PlayCtrl.PlayM4_OpenStream(m_lPort, ref pBuffer, dwBufSize, 1024 * 1024))
                        {
                            m_lPort = -1;
                            //this.BeginInvoke(AlarmInfo, "PlayM4_OpenStream fail");
                            break;
                        }


                        //set soft decode display callback function to capture
                        m_fDisplayFun = new PlayCtrl.DISPLAYCBFUN(RemoteDisplayCBFun);
                        if (!PlayCtrl.PlayM4_SetDisplayCallBack(m_lPort, m_fDisplayFun))
                        {
                            //this.BeginInvoke(AlarmInfo, "PlayM4_SetDisplayCallBack fail");
                        }

                        //start play, set play window
                        //this.BeginInvoke(AlarmInfo, "About to call PlayM4_Play");

                        if (!PlayCtrl.PlayM4_Play(m_lPort, m_ptrRealHandle))
                        {
                            m_lPort = -1;
                            //this.BeginInvoke(AlarmInfo, "PlayM4_Play fail");
                            break;
                        }


                        //set frame buffer number

                        if (!PlayCtrl.PlayM4_SetDisplayBuf(m_lPort, 15))
                        {
                            //this.BeginInvoke(AlarmInfo, "PlayM4_SetDisplayBuf fail");
                        }

                        //set display mode
                        if (!PlayCtrl.PlayM4_SetOverlayMode(m_lPort, 0, 0/* COLORREF(0)*/))//play off screen // todo!!!
                        {
                            //this.BeginInvoke(AlarmInfo, " PlayM4_SetOverlayMode fail");
                        }

                    }

                    break;
                case CHCNetSDK.NET_DVR_STREAMDATA:     // video stream data
                    if (dwBufSize > 0 && m_lPort != -1)
                    {
                        if (!PlayCtrl.PlayM4_InputData(m_lPort, ref pBuffer, dwBufSize))
                        {
                            //this.BeginInvoke(AlarmInfo, " PlayM4_InputData fail");
                        }
                    }
                    break;

                case CHCNetSDK.NET_DVR_AUDIOSTREAMDATA:     //  Audio Stream Data
                    if (dwBufSize > 0 && m_lPort != -1)
                    {
                        if (!PlayCtrl.PlayM4_InputVideoData(m_lPort, ref pBuffer, dwBufSize))
                        {
                            //this.BeginInvoke(AlarmInfo, "PlayM4_InputVideoData Fail");
                        }
                    }

                    break;
                default:
                    break;
            }

        }

         public void DrawFunCallBack(Int32 lRealHandle, IntPtr hDc, uint pUser)
        {
            Graphics g = Graphics.FromHdc(hDc);
            Pen m_pen = new Pen(Color.Blue, 1);
            //设置虚线格式 
            m_pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
            g.DrawRectangle(m_pen, Convert.ToInt32(PicX * PicCurrent.Width), Convert.ToInt32(startPoint.Y * PicCurrent.Width), Convert.ToInt32(PicW * PicCurrent.Width), Convert.ToInt32(PicH * PicCurrent.Height));
        }

 private void D()
 {
                    if (m_lRealHandle != -1)
            {
                uint dwUser = 0;
                m_drawFun = new CHCNetSDK.DRAWFUN(DrawFunCallBack);
                CHCNetSDK.NET_DVR_RigisterDrawFun(m_lRealHandle, m_drawFun, dwUser);
            }
}

                        //调用预览
                        lpClientInfo.hPlayWnd = IntPtr.Zero;
                        //lpClientInfo.sMultiCastIP = "";
                        m_ptrRealHandle = PicCurrent.Handle;
                        m_fRealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack);
                        m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V30(m_lUserID, ref lpClientInfo, m_fRealData, pUser, 1);


                                                //之后调用D()
                                                D()

c#

3个回答

打开预览时的函数传入的参数中,回调函数应该设置为null,
m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null/*RealData*/, pUser);
m_drawFun = new CHCNetSDK.DRAWFUN(DrawFunCallBack);

无法进入回调函数DrawFunCallBack提示什么错误?

lc17273747
lc17273747 你这个应该是句柄参数没有设置好,能否发一份稍微完整点的代码给我,我帮你看一下?417051380@qq.com
4 年多之前 回复
hero_heart
hero_heart 无法进入回调函数DrawFunCallBack 请问解决了吗?我也碰到这个问题? 没有一点头绪
5 年多之前 回复
yimuxuewen
yimuxuewen 错误号为12(调用次序错误)。
5 年多之前 回复

应该是你的回调函数没有设置正确给sdk,所以反过来sdk没有调用你的callback

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐