tags:

views:

974

answers:

2

I am using some C++ code that employs the CreateDIBSection function to create a bitmap and return a HBITMAP handle. What is the best way of getting this information into my .NET assembly?

A: 

Have you tried marshalling the byte array for your bitmap across, loading it into a MemoryStream and then using that stream to construct a Bitmap class?

Rob Prouse
+5  A: 

The static method Image.FromHbitmap(IntPtr hbitmap) might be what you are looking for.

Darin Dimitrov
But do I have to release the bitmap from C#?
Dmitri Nesteruk
Yes, you can call Dispose(): using (Bitmap bmp = Image.FromHbitmap(hbitmap)) { /* Do some work with the bitmap */ }
Darin Dimitrov