yimuxuewen
yimuxuewen
采纳率100%
2015-01-27 13:19

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()

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • yimuxuewen yimuxuewen 6年前

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

    点赞 评论 复制链接分享
  • caozhy 从今以后生命中的每一秒都属于我爱的人 6年前

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

    点赞 1 评论 复制链接分享
  • oyljerry oyljerry 6年前

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

    点赞 评论 复制链接分享

相关推荐