通过C++读取视频图像后想要将视频图像数据实时在C#中使用,但是拷贝内存导致了帧率下降,请问什么办法能够使得C#直接读取C++分配的这块内存里的数据?

解决方案 »

  1.   

    两种方式
    1.c++ 自己将数据通过http请求提交到 asp.net 网站,
    2.asp.net 网站部分编写一个webservice,供c++调用 
      

  2.   

    你可以用IntPtr返回内存指针(在c++中是DWORD在c#中是IntPtr),然后在c#中用unsafe代码使用指针处理这些数据,不过这样做不好,
      

  3.   

    以前在C#里做过和VC的数据交互,十分郁闷呀,数据是能取到,但是一会儿就出错了。
    最后推测是C#自动回收内存造成的。
      

  4.   


    C++函数
    /// Return Type: void
                ///player: CFlashPlayer*
                ///buffer: void**
                ///width: int*
                ///height: int*
                ///stride: int*
                ///format: int*
                ///获取当前的图像的内存
                [System.Runtime.InteropServices.DllImportAttribute("XSwfDec.dll", EntryPoint = "flashplayer_get_current_bitmap", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
                public static extern void flashplayer_get_current_bitmap(ref System.IntPtr buffer, ref int width, ref int height, ref int stride, ref int format);
    C#使用
    #region 获得当前的内存中的位图            IntPtr bufferPtr = IntPtr.Zero;
                int width =0;
                int height =0;
                int stride =0;
                int format =0;
                XSwfPlayerforWin.NativeMethods.flashplayer_get_current_bitmap(ref bufferPtr, ref width, ref height, ref stride, ref format);
                XSwfPlayerforWin.NativeMethods.flashplayer_pause();
                
                Bitmap bit = new Bitmap(width, height, stride, (System.Drawing.Imaging.PixelFormat)format, bufferPtr);
                objcrop.CropImage = (Image)bit;
                #endregion
      

  5.   

    我们现在的用的就是这样的。不c++的dll 直接绑定了一个handle。
    c#只要传一个控件的句柄就可以了。
      

  6.   

    涉及到应用程序间的数据交换问题,你可以使用webservice来实现。
      

  7.   

    拷贝内存尚且丢帧,就不应该有人硬往web service这种东西上套了。
      

  8.   

    平台调用N多次,没出现没什么问题,注意数据类型的对应。C++可以传一个指针,C#里用Intptr