Bitmap.GetHbitmap Method (Color)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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(
	Color background


Type: System.Drawing.Color

A Color structure that specifies the background color. This parameter is ignored if the bitmap is totally opaque.

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.

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

    // Do something with hBitmap.


for calling into unmanaged code. Related enumeration: UnmanagedCode

.NET Framework
Available since 1.1
Return to top