I am writing a program to render a map as a in-memory Bitmap that then sends the data to another application.
I've followed the ExportJpg example here.
The problem is the exporter creates a GDI HBitmap. I want a .Net Bitmap so I'm using Systems.Drawing.Image.FromHbitmap()
Microsoft sdk Image.FromHbitmap Method (IntPtr) (System.Drawing) says that you have to use the gdi32.dll call to DeleteObject() to release the GDI Object manually after using FromHbitmap().
What I am finding is that the GDI handle that is created by FromHBitmap is never released and the program leaks a GDI Object every time the new bmp is exported.
// activeView and exportBmpClass are already setup similar to ExportJPJ example Int32 hDC = exportBmpClass.StartExporting(); // Creates 1 DC and 1 HBitmap activeView.Output(hDC, (int)exportBmpClass.Resolution, ref exRect, null, null); //renders activeview to the hDC/ HBitmap Bitmap bmp = Image.FromHbitmap((IntPtr)exportBmpClass.Bitmap, (IntPtr)exportBmpClass.Palette); // creates 1 HBitmap DeleteObject((IntPtr)exportBmpClass.Bitmap); // gdi32.dll call does not release a HBitmap! exportBmpClass.FinishExporting(); // releases 1 DC exportBmpClass.Cleanup(); //releases 1 HBitmap // rest of code, do stuff with the .Net bmp ...