Bitmap::GetHbitmap Method ()

 

Creates a GDI bitmap object from this Bitmap.

Namespace:   System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public:
[SecurityPermissionAttribute(SecurityAction::LinkDemand, Flags = SecurityPermissionFlag::UnmanagedCode)]
IntPtr GetHbitmap()

Return Value

Type: System::IntPtr

A handle to the GDI bitmap object that this method creates.

Exception Condition
ArgumentException

The height or width of the bitmap is greater than MaxValue.

Exception

The operation failed.

You are responsible for calling the GDI DeleteObject method to free the memory used by the GDI bitmap object. For more information about GDI bitmaps, see Bitmaps in the Windows GDI documentation.

The following code example demonstrates how to use the GetHbitmap method.

   [System::Runtime::InteropServices::DllImportAttribute("gdi32.dll")]
   static bool DeleteObject( IntPtr hObject );

private:
   void DemonstrateGetHbitmap()
   {
      Bitmap^ bm = gcnew Bitmap( "Picture.jpg" );
      IntPtr hBitmap = bm->GetHbitmap();

      // Do something with hBitmap.
      DeleteObject( hBitmap );
   }

SecurityPermission

for calling into unmanaged code. Related enumeration: UnmanagedCode

.NET Framework
Available since 1.1
Return to top
Show: