C#传数据到c++,需要编译c++的dll库,这里不具体介绍如何编译dll库。
C#:
- 声明接口
[DllImport("dllmake")]
private unsafe static extern bool detectAndDraw(byte[] ImageBuffer, byte[] ImageBuffer1, int imageWeidth, int imageHeight, byte[] data);
- 调用接口
bool flag = detectAndDraw(rgbValues, rgbValues1, ImageWeidth, ImageHeight, pstdata);
- 将图片读成byte[]
注:不能直接用IO将图片读成byte[]数组,如果直接用IO都城数组,那传过去的数据将不能生成一幅图片,需要借助c#的集成库(System.Drawing.dll), ## System.Drawing.dll
Bitmap bmp = (Bitmap)Image.FromFile("src.jpg");
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData =
bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);