Bitmap.GetHbitmap 方法

定義

從 GDI+ Bitmap 建立 GDI 點陣圖物件。

多載

GetHbitmap()

從這個 Bitmap 建立 GDI 點陣圖物件。

GetHbitmap(Color)

從這個 Bitmap 建立 GDI 點陣圖物件。

GetHbitmap()

來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs

從這個 Bitmap 建立 GDI 點陣圖物件。

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

傳回

IntPtr

nativeint

這個方法所建立之 GDI 點陣圖物件的控制碼。

例外狀況

點陣圖的高度或寬度大於 Int16.MaxValue

作業失敗。

範例

下列程式碼範例會示範如何使用 GetHbitmap 方法。

   [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

備註

您必須負責呼叫 GDI DeleteObject 方法,以釋放 GDI 點陣圖物件所使用的記憶體。 如需 GDI 點陣圖的詳細資訊,請參閱 Windows GDI 檔中的 點陣圖

適用於

GetHbitmap(Color)

來源:
Bitmap.cs
來源:
Bitmap.cs
來源:
Bitmap.cs

從這個 Bitmap 建立 GDI 點陣圖物件。

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 結構,指定背景色彩。 如果點陣圖完全不透明,這個參數會被忽略。

傳回

IntPtr

nativeint

這個方法所建立之 GDI 點陣圖物件的控制碼。

例外狀況

點陣圖的高度或寬度大於 Int16.MaxValue

作業失敗。

範例

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

備註

您必須負責呼叫 GDI DeleteObject 方法,以釋放 GDI 點陣圖物件所使用的記憶體。 如需 GDI 點陣圖的詳細資訊,請參閱 Windows GDI 檔中的 點陣圖

適用於