Icon.ToBitmap 方法  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
public:
 System::Drawing::Bitmap ^ ToBitmap();public System.Drawing.Bitmap ToBitmap ();member this.ToBitmap : unit -> System.Drawing.BitmapPublic Function ToBitmap () As Bitmap返回
示例
下面的代码示例演示如何使用 ToBitmap 方法。 此示例旨在与 Windows 窗体 一起使用。 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" />