Bitmap.GetHbitmap Method ()


Creates a GDI bitmap object from this Bitmap.

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

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

Return Value

Type: System.IntPtr

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

Exception Condition

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


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.

public static extern bool DeleteObject(IntPtr hObject);

private void DemonstrateGetHbitmap()
    Bitmap bm = new Bitmap("Picture.jpg");
    IntPtr hBitmap = bm.GetHbitmap();

    // Do something with hBitmap.


for calling into unmanaged code. Related enumeration: UnmanagedCode

.NET Framework
Available since 1.1
Return to top