求助关于C#与C++之间的数据传输问题 通过C++读取视频图像后想要将视频图像数据实时在C#中使用,但是拷贝内存导致了帧率下降,请问什么办法能够使得C#直接读取C++分配的这块内存里的数据? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 两种方式1.c++ 自己将数据通过http请求提交到 asp.net 网站,2.asp.net 网站部分编写一个webservice,供c++调用 你可以用IntPtr返回内存指针(在c++中是DWORD在c#中是IntPtr),然后在c#中用unsafe代码使用指针处理这些数据,不过这样做不好, 以前在C#里做过和VC的数据交互,十分郁闷呀,数据是能取到,但是一会儿就出错了。最后推测是C#自动回收内存造成的。 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 我们现在的用的就是这样的。不c++的dll 直接绑定了一个handle。c#只要传一个控件的句柄就可以了。 涉及到应用程序间的数据交换问题,你可以使用webservice来实现。 拷贝内存尚且丢帧,就不应该有人硬往web service这种东西上套了。 平台调用N多次,没出现没什么问题,注意数据类型的对应。C++可以传一个指针,C#里用Intptr C#邮件研究 WPF ComboBox绑定集合,并根据集合中每个元素的特征决定是否禁止该项 显示信号输出的问题 vs2008做rdlc报表问题 开发手机软件,如何上网? 读取一个字符串时,遇到"= "号 ,(也就是号后的不读出来) 就让他读到下一行。怎么写? 求助!关于用C#获取一个活动窗口句柄的问题 长沙的可以去试试,我失败了 关于开发三层应用程序(分布式程序)数据在表示层和数据层以何种形式传输。 程序错误 Js中取RadioButtonList值的问题 听说httpwebreqeust也有同步异步,那么跟线程的同异步有什么区别呢?
1.c++ 自己将数据通过http请求提交到 asp.net 网站,
2.asp.net 网站部分编写一个webservice,供c++调用
最后推测是C#自动回收内存造成的。
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
c#只要传一个控件的句柄就可以了。