แก้ไข

แชร์ผ่าน


Bitmap.GetHbitmap Method

Definition

Creates a GDI bitmap object from a GDI+ Bitmap.

Overloads

GetHbitmap()

Creates a GDI bitmap object from this Bitmap.

GetHbitmap(Color)

Creates a GDI bitmap object from this Bitmap.

GetHbitmap()

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

IntPtr

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

GetHbitmap(Color)

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

IntPtr

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