Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Here is what I have:

  • An external DLL, I have written in C. This DLL links to opencv. I don't want to call OpenCV directly from C# - there are already huge amounts of C code accessing OpenCV which will be used in the DLL. There is an exported function: passbitmap(void *mem, size_t s);

  • A C# project from which I want to call the DLL.

  • A System.Drawing.Bitmap object from which I want to pass the pixel/bitmap data somehow to my DLL.

I guess its some kind of P/Invoke, but I have never done it, and don't know how can I do it properly in this case. How should I proceed?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
539 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to call Bitmap.GetHbitmap() to get the native handle to the bitmap.

Then you basically want to do some native interop and call GetDIBits(). It may be better to have your target dll actually call GetDIBits() and just pass the win32 handle, rather than do the interop.

You'll need to call CreateCompatibleDC() on the desktop DC which you get from GetDC(NULL), then CreateCompatibleBitmap() on the DC you just made. Then call GetDIBits().


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...