Bitmap.GetHbitmap Bitmap.GetHbitmap Bitmap.GetHbitmap Bitmap.GetHbitmap Method

定義

從 GDI+ Bitmap 建立 GDI 點陣圖物件。Creates a GDI bitmap object from a GDI+ Bitmap.

多載

GetHbitmap() GetHbitmap() GetHbitmap() GetHbitmap()

從這個 Bitmap 建立 GDIGDI 點陣圖物件。Creates a GDIGDI bitmap object from this Bitmap.

GetHbitmap(Color) GetHbitmap(Color) GetHbitmap(Color) GetHbitmap(Color)

從這個 Bitmap 建立 GDIGDI 點陣圖物件。Creates a GDIGDI bitmap object from this Bitmap.

GetHbitmap() GetHbitmap() GetHbitmap() GetHbitmap()

從這個 Bitmap 建立 GDIGDI 點陣圖物件。Creates a GDIGDI bitmap object from this Bitmap.

public:
 IntPtr GetHbitmap();
public IntPtr GetHbitmap ();
member this.GetHbitmap : unit -> nativeint
Public Function GetHbitmap () As IntPtr

傳回

這個方法所建立的 GDIGDI 點陣圖物件的控制代碼。A handle to the GDIGDI bitmap object that this method creates.

例外狀況

點陣圖的寬度或高度大於 MaxValueThe height or width of the bitmap is greater than MaxValue.

作業失敗。The operation failed.

範例

下列程式碼範例會示範如何使用 GetHbitmap 方法。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

備註

您必須負責呼叫GDIGDIDeleteObject方法來釋放所使用的記憶體GDIGDI點陣圖物件。You are responsible for calling the GDIGDI DeleteObject method to free the memory used by the GDIGDI bitmap object. 如需 GDI 點陣圖的詳細資訊,請參閱點陣圖Windows GDI 文件中。For more information about GDI bitmaps, see Bitmaps in the Windows GDI documentation.

安全性

SecurityPermission
呼叫進入 unmanaged 程式碼。for calling into unmanaged code. 相關的列舉型別: UnmanagedCodeRelated enumeration: UnmanagedCode

GetHbitmap(Color) GetHbitmap(Color) GetHbitmap(Color) GetHbitmap(Color)

從這個 Bitmap 建立 GDIGDI 點陣圖物件。Creates a GDIGDI 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

參數

background
Color Color Color Color

Color 結構,指定背景色彩。A Color structure that specifies the background color. 如果點陣圖完全不透明,這個參數會被忽略。This parameter is ignored if the bitmap is totally opaque.

傳回

這個方法所建立的 GDIGDI 點陣圖物件的控制代碼。A handle to the GDIGDI bitmap object that this method creates.

例外狀況

點陣圖的寬度或高度大於 MaxValueThe height or width of the bitmap is greater than MaxValue.

作業失敗。The operation failed.

範例

下列程式碼範例示範如何使用GetHbitmap.method。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

備註

您必須負責呼叫GDIGDIDeleteObject方法來釋放所使用的記憶體GDIGDI點陣圖物件。You are responsible for calling the GDIGDI DeleteObject method to free the memory used by the GDIGDI bitmap object. 如需 GDI 點陣圖的詳細資訊,請參閱點陣圖Windows GDI 文件中。For more information about GDI bitmaps, see Bitmaps in the Windows GDI documentation.

安全性

SecurityPermission
呼叫進入 unmanaged 程式碼。for calling into unmanaged code. 相關的列舉型別: UnmanagedCodeRelated enumeration: UnmanagedCode

適用於