Icon.ToBitmap 方法

定義

將這個 Icon 轉換成 GDI+ Bitmap

public:
 System::Drawing::Bitmap ^ ToBitmap();
public System.Drawing.Bitmap ToBitmap ();
member this.ToBitmap : unit -> System.Drawing.Bitmap
Public Function ToBitmap () As Bitmap

傳回

Bitmap,表示已轉換的 Icon

範例

下列程式碼範例會示範如何使用 ToBitmap 方法。 此範例的設計目的是要與 Windows Forms 搭配使用。 Create 表單,並將下列程式代碼貼到窗體中。 IconToBitmap在表單的 .Paint 事件處理程式中呼叫 方法,傳遞ePaintEventArgs

private:
   void IconToBitmap( PaintEventArgs^ e )
   {
      // Construct an Icon.
      System::Drawing::Icon^ icon1 = gcnew System::Drawing::Icon( SystemIcons::Exclamation,40,40 );

      // Call ToBitmap to convert it.
      Bitmap^ bmp = icon1->ToBitmap();

      // Draw the bitmap.
      e->Graphics->DrawImage( bmp, Point(30,30) );
   }
private void IconToBitmap(PaintEventArgs e)
{
    // Construct an Icon.
    Icon icon1 = new Icon(SystemIcons.Exclamation, 40, 40);

    // Call ToBitmap to convert it.
    Bitmap bmp = icon1.ToBitmap();

    // Draw the bitmap.
    e.Graphics.DrawImage(bmp, new Point(30, 30));
}
Private Sub IconToBitmap(ByVal e As PaintEventArgs)

    ' Construct an Icon.
    Dim icon1 As New Icon(SystemIcons.Exclamation, 40, 40)

    ' Call ToBitmap to convert it.
    Dim bmp As Bitmap = icon1.ToBitmap()

    ' Draw the bitmap.
    e.Graphics.DrawImage(bmp, New Point(30, 30))
End Sub

備註

當圖示轉換成位陣圖時,圖示的透明區域就會遺失,而產生的點陣圖的透明色彩會設定為 RGB(13,11,12)。 傳回的點陣圖的高度和寬度與原始圖示相同。

注意

從架構 4.6 版開始,已針對 .ico 檔案中的 PNG 畫面新增支援。 以舊版架構為目標但正在 4.6 位上執行的應用程式,可以將下列這一行新增至 <runtime> app.config 檔案的 區段,以選擇加入新行為:<AppContextSwitchOverrides value="Switch.System.Drawing.DontSupportPngFramesInIcons=false" />

適用於