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?
views:
974answers:
2
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
2008-12-04 18:47:14
+5
A:
The static method Image.FromHbitmap(IntPtr hbitmap) might be what you are looking for.
Darin Dimitrov
2008-12-04 18:52:41
But do I have to release the bitmap from C#?
Dmitri Nesteruk
2008-12-04 19:19:31
Yes, you can call Dispose(): using (Bitmap bmp = Image.FromHbitmap(hbitmap)) { /* Do some work with the bitmap */ }
Darin Dimitrov
2008-12-04 19:23:01