How to get hDIB from .NET/C# Bitmap control

I am using a third-party image analysis toolkit that wants me to pass in a Windows hDIB. I can't determine how to get a DIB (even a copy) from the standard .net Bitmap control.

The third-party toolkit sees and "hDIB" as an Int.
Who is Participating?
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
That's because it wants a Handle to a bitmap. Try something like:

Bitmap bmp = (Bitmap)Bitmap.FromFile("Somefile.bmp");

Open in new window

LarryBoyColoradoAuthor Commented:
Found out you need to free the object as well (example from MSDN)...

using System.Runtime.InteropServices;
public static extern bool DeleteObject(IntPtr hObject);
Bitmap bm = new Bitmap("Picture.jpg");
IntPtr hBitmap = bm.GetHbitmap();
// Do something with hBitmap.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.