Bitmap.GetHbitmap Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates a GDI bitmap object from a GDI+ Bitmap.
GetHbitmap() |
Creates a GDI bitmap object from this Bitmap. |
GetHbitmap(Color) |
Creates a GDI bitmap object from this Bitmap. |
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
Creates a GDI bitmap object from this Bitmap.
public:
IntPtr GetHbitmap();
public IntPtr GetHbitmap();
member this.GetHbitmap : unit -> nativeint
Public Function GetHbitmap () As IntPtr
Returns
nativeint
A handle to the GDI bitmap object that this method creates.
Exceptions
The height or width of the bitmap is greater than Int16.MaxValue.
The operation failed.
Examples
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 );
}
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
private void DemonstrateGetHbitmap()
{
Bitmap bm = new Bitmap("Picture.jpg");
IntPtr hBitmap = bm.GetHbitmap();
// Do something with hBitmap.
DeleteObject(hBitmap);
}
<System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")> _
Private Shared Function DeleteObject (ByVal hObject As IntPtr) As Boolean
End Function
Private Sub DemonstrateGetHbitmap()
Dim bm As New Bitmap("Picture.jpg")
Dim hBitmap As IntPtr
hBitmap = bm.GetHbitmap()
' Do something with hBitmap.
DeleteObject(hBitmap)
End Sub
Remarks
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.
Applies to
.NET 10 (package-provided) and other versions
Product | Versions |
---|---|
.NET | 8 (package-provided), 9 (package-provided), 10 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
Creates a GDI bitmap object from this Bitmap.
public:
IntPtr GetHbitmap(System::Drawing::Color background);
public IntPtr GetHbitmap(System.Drawing.Color background);
member this.GetHbitmap : System.Drawing.Color -> nativeint
Public Function GetHbitmap (background As Color) As IntPtr
Parameters
- background
- Color
A Color structure that specifies the background color. This parameter is ignored if the bitmap is totally opaque.
Returns
nativeint
A handle to the GDI bitmap object that this method creates.
Exceptions
The height or width of the bitmap is greater than Int16.MaxValue.
The operation failed.
Examples
The following code example demonstrates how to use the GetHbitmap.method.
void DemonstrateGetHbitmapWithColor()
{
Bitmap^ bm = gcnew Bitmap( "Picture.jpg" );
IntPtr hBitmap = bm->GetHbitmap( Color::Blue );
// Do something with hBitmap.
DeleteObject( hBitmap );
}
private void DemonstrateGetHbitmapWithColor()
{
Bitmap bm = new Bitmap("Picture.jpg");
IntPtr hBitmap = bm.GetHbitmap(Color.Blue);
// Do something with hBitmap.
DeleteObject(hBitmap);
}
Private Sub DemonstrateGetHbitmapWithColor()
Dim bm As New Bitmap("Picture.jpg")
Dim hBitmap As IntPtr
hBitmap = bm.GetHbitmap(Color.Blue)
' Do something with hBitmap.
DeleteObject(hBitmap)
End Sub
Remarks
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.
Applies to
.NET 10 (package-provided) and other versions
Product | Versions |
---|---|
.NET | 8 (package-provided), 9 (package-provided), 10 (package-provided) |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0 (package-provided) |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: