I am writing a C++/Cli interop layer that sits between a native library providing image read from disk using opencv. The interop layer should convert the image to a managed bitmap, then send it to a c# ui.
The actual conversion is trivial by copying the memory. The problem is, this application must process many large images, so it is very resource intensive. Because of this, I would like to avoid keeping two copies of the image in memory, and rather reassign the pointer to the image data in the managed bitmap to point to the opencv image data.
My initial thought was that I could just lock the managed bitmap and assign the Scan0 pointer to the opencv pointer, then make sure the Stride was set to the widthStep of the opencv image (I am using a normal IplImage), but when I do this, the image that comes out is completely black.
Is there any way to create a managed Bitmap without copying the native image data into it?
Thanks,
Max
Turns out there is a constructor provided that can do this, see
http://msdn.microsoft.com/en-us/library/zy1a2d14.aspx
make sure the opencv image isnt going out of scope though!