Icon.ToBitmap Méthode

Définition

Convertit ce Icon en Bitmap GDI+.

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

Retours

Bitmap qui représente le Icon converti.

Exemples

L'exemple de code suivant illustre l'utilisation de la méthode ToBitmap. Cet exemple est conçu pour être utilisé avec Windows Forms. Create un formulaire et collez-y le code suivant. Appelez la IconToBitmap méthode dans le gestionnaire d’événements .Paint du formulaire, en passant comme 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

Remarques

Les zones transparentes de l’icône sont perdues lorsqu’elle est convertie en bitmap, et la couleur transparente de la bitmap résultante est définie sur RGB(13,11,12). La bitmap retournée a la même hauteur et la même largeur que l’icône d’origine.

Notes

À compter de la version 4.6 du framework, la prise en charge des images PNG a été ajoutée dans les fichiers .ico. Les applications qui ciblent des versions antérieures de l’infrastructure, mais qui s’exécutent sur les 4,6 bits, peuvent accepter le nouveau comportement en ajoutant la ligne suivante à la <runtime> section du fichier app.config :<AppContextSwitchOverrides value="Switch.System.Drawing.DontSupportPngFramesInIcons=false" />

S’applique à