Icon.ToBitmap Método

Definição

Converte este Icon em um Bitmap GDI+.

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

Retornos

Um Bitmap que representa o Icon convertido.

Exemplos

O exemplo de código a seguir demonstra como usar o ToBitmap método . Este exemplo foi projetado para ser usado com Windows Forms. Create um formulário e cole o código a seguir nele. Chame o IconToBitmap método no manipulador de eventos .Paint do formulário, passando e como 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

Comentários

As áreas transparentes do ícone são perdidas quando ele é convertido em um bitmap e a cor transparente do bitmap resultante é definida como RGB(13,11,12). O bitmap retornado tem a mesma altura e largura que o ícone original.

Observação

A partir da estrutura, o suporte à versão 4.6 foi adicionado para quadros PNG em arquivos .ico. Aplicativos direcionados a versões anteriores da estrutura, mas que estão em execução nos 4,6 bits, podem aceitar o novo comportamento adicionando a seguinte linha à <runtime> seção do arquivo app.config:<AppContextSwitchOverrides value="Switch.System.Drawing.DontSupportPngFramesInIcons=false" />

Aplica-se a