When building a bitmap with Image.FromHbitmap (), how soon can the original bitmap handler be removed?

From the documentation Image.FromHbitmap()at http://msdn.microsoft.com/en-us/library/k061we7x%28VS.80%29.aspx :

The FromHbitmap method makes a copy of the GDI bitmap; therefore, you can free the incoming GDI bitmap using the GDIDeleteObject method immediately after creating a new image.

This pretty clearly indicates that the bitmap descriptor can be deleted immediately with DeleteObject as soon as the Bitmap instance is created.

However, looking at the implementation Image.FromHbitmap()with Reflector, it shows that it is a pretty thin shell around the GDI +, function GdipCreateBitmapFromHBITMAP().

There is quite scanty documentation Function API GDI +, but http://msdn.microsoft.com/en-us/library/ms533971%28VS.85%29.aspx says that GdipCreateBitmapFromHBITMAP()corresponds to Bitmap::Bitmap()a constructor that takes no parameters HBITMAPand HPALETTE.

The documentation for this version of the constructor Bitmap::Bitmap()at http://msdn.microsoft.com/en-us/library/ms536314%28VS.85%29.aspx says the following:

You are responsible for removing the GDI bitmap and the GDI palette. However, you must not delete the GDI bitmap or GDI palette until the GDI + Bitmap :: Bitmap object is deleted or deleted.

Do not pass the GDI bitmap or GDI palette that is currently (or was previously) selected in the device context to the GDI + Bitmap :: Bitmap constructor.

, ++- GDI + GdiPlusBitmap.h , Bitmap::Bitmap() GdipCreateBitmapFromHBITMAP() API:

inline 
Bitmap::Bitmap(
    IN HBITMAP hbm, 
    IN HPALETTE hpal
    )
{
    GpBitmap *bitmap = NULL;

    lastResult = DllExports::GdipCreateBitmapFromHBITMAP(hbm, hpal, &bitmap);

    SetNativeImage(bitmap);
}

, , - GdipCreateBitmapFromHBITMAP(), , . .Net , , GDI + , - , GDI +.

, GDI + HBITMAP, . , , , , . , , GDI +, GDI.

, :

  • - .Net Bitmap?
  • GDI + GdipCreateBitmapFromHBITMAP() ?
  • HBITMAP, ?
+5
1

, .Net . DeleteObject() HBITMAP, Image.FromHbitmap(), , , .

, , GDI + Bitmap::Bitmap() GDI + GdipCreateBitmapFromHBITMAP(), .

, GDI + - HBITMAP. GDI +, .Net , , , GDI +.

+2

All Articles