Icon.ToBitmap Methode

Definition

Konvertiert dieses Icon in eine GDI+-Bitmap.

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

Gibt zurück

Eine Bitmap, die das konvertierte Icon darstellt.

Beispiele

Das folgende Codebeispiel zeigt, wie Sie die ToBitmap-Methode verwenden. Dieses Beispiel ist für die Verwendung mit Windows Forms konzipiert. Create ein Formular, und fügen Sie den folgenden Code ein. Rufen Sie die IconToBitmap -Methode im Ereignishandler des Formulars auf,Paint und übergeben Sie e als PaintEventArgs .

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

Hinweise

Die transparenten Bereiche des Symbols gehen verloren, wenn es in eine Bitmap konvertiert wird, und die transparente Farbe der resultierenden Bitmap ist auf RGB(13,11,12)festgelegt. Die zurückgegebene Bitmap hat die gleiche Höhe und Breite wie das ursprüngliche Symbol.

Hinweis

Ab Frameworkversion 4.6 wurde Unterstützung für PNG-Frames in .ico-Dateien hinzugefügt. Anwendungen, die auf frühere Versionen des Frameworks abzielen, aber mit den 4,6-Bits ausgeführt werden, können das neue Verhalten aktivieren, indem sie dem Abschnitt der app.config-Datei die <runtime> folgende Zeile hinzufügen:<AppContextSwitchOverrides value="Switch.System.Drawing.DontSupportPngFramesInIcons=false" />

Gilt für: