Bitmap.MakeTransparent Método

Definição

Torna a cor transparente padrão transparente para este Bitmap.

Sobrecargas

MakeTransparent()

Torna a cor transparente padrão transparente para este Bitmap.

MakeTransparent(Color)

Torna a cor especificada transparente para este Bitmap.

MakeTransparent()

Origem:
Bitmap.cs
Origem:
Bitmap.cs
Origem:
Bitmap.cs

Torna a cor transparente padrão transparente para este Bitmap.

public:
 void MakeTransparent();
public void MakeTransparent ();
member this.MakeTransparent : unit -> unit
Public Sub MakeTransparent ()

Exceções

O formato da imagem do Bitmap é um formato de ícone.

Falha na operação.

Exemplos

O exemplo de código a seguir foi projetado para uso com Windows Forms e requer PaintEventArgse, que é um parâmetro do Paint manipulador de eventos. O código torna a cor transparente padrão do sistema transparente para myBitmape desenha a Bitmap na tela.

private:
   void MakeTransparent_Example1( PaintEventArgs^ e )
   {
      // Create a Bitmap object from an image file.
      Bitmap^ myBitmap = gcnew Bitmap( "Grapes.gif" );

      // Draw myBitmap to the screen.
      e->Graphics->DrawImage( myBitmap, 0, 0, myBitmap->Width, myBitmap->Height );

      // Make the default transparent color transparent for myBitmap.
      myBitmap->MakeTransparent();

      // Draw the transparent bitmap to the screen.
      e->Graphics->DrawImage( myBitmap, myBitmap->Width, 0, myBitmap->Width, myBitmap->Height );
   }
private void MakeTransparent_Example1(PaintEventArgs e)
{

    // Create a Bitmap object from an image file.
    Bitmap myBitmap = new Bitmap("Grapes.gif");

    // Draw myBitmap to the screen.
    e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width,
        myBitmap.Height);

    // Make the default transparent color transparent for myBitmap.
    myBitmap.MakeTransparent();

    // Draw the transparent bitmap to the screen.
    e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0,
        myBitmap.Width, myBitmap.Height);
}
Private Sub MakeTransparent_Example1(ByVal e As PaintEventArgs)

    ' Create a Bitmap object from an image file.
    Dim myBitmap As New Bitmap("Grapes.gif")

    ' Draw myBitmap to the screen.
    e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, _
    myBitmap.Height)

    ' Make the default transparent color transparent for myBitmap.
    myBitmap.MakeTransparent()

    ' Draw the transparent bitmap to the screen.
    e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, _
    myBitmap.Height)
End Sub

Comentários

A paleta do sistema define uma cor como a cor transparente ou alfa padrão. Esse método torna a cor transparente padrão transparente para este Bitmap. Se nenhuma cor transparente for especificada pelo sistema, LightGray será a cor transparente.

Quando você chamar MakeTransparent, o bitmap será convertido no Format32bppArgb formato , pois esse formato dá suporte a um canal alfa.

Aplica-se a

MakeTransparent(Color)

Origem:
Bitmap.cs
Origem:
Bitmap.cs
Origem:
Bitmap.cs

Torna a cor especificada transparente para este Bitmap.

public:
 void MakeTransparent(System::Drawing::Color transparentColor);
public void MakeTransparent (System.Drawing.Color transparentColor);
member this.MakeTransparent : System.Drawing.Color -> unit
Public Sub MakeTransparent (transparentColor As Color)

Parâmetros

transparentColor
Color

A estrutura Color que representa a cor para tornar transparente.

Exceções

O formato da imagem do Bitmap é um formato de ícone.

Falha na operação.

Exemplos

O exemplo de código a seguir foi projetado para uso com Windows Forms e requer PaintEventArgse, que é um parâmetro do Paint manipulador de eventos. O código executa as seguintes ações:

  • Obtém a cor de um pixel em um Bitmap.

  • Torna essa cor transparente para o bitmap.

  • Desenha o Bitmap na tela.

private:
   void MakeTransparent_Example2( PaintEventArgs^ e )
   {
      // Create a Bitmap object from an image file.
      Bitmap^ myBitmap = gcnew Bitmap( "Grapes.gif" );

      // Draw myBitmap to the screen.
      e->Graphics->DrawImage( myBitmap, 0, 0, myBitmap->Width, myBitmap->Height );

      // Get the color of a background pixel.
      Color backColor = myBitmap->GetPixel( 1, 1 );

      // Make backColor transparent for myBitmap.
      myBitmap->MakeTransparent( backColor );

      // Draw the transparent bitmap to the screen.
      e->Graphics->DrawImage( myBitmap, myBitmap->Width, 0, myBitmap->Width, myBitmap->Height );
   }
private void MakeTransparent_Example2(PaintEventArgs e)
{

    // Create a Bitmap object from an image file.
    Bitmap myBitmap = new Bitmap("Grapes.gif");

    // Draw myBitmap to the screen.
    e.Graphics.DrawImage(
        myBitmap, 0, 0, myBitmap.Width, myBitmap.Height);

    // Get the color of a background pixel.
    Color backColor = myBitmap.GetPixel(1, 1);

    // Make backColor transparent for myBitmap.
    myBitmap.MakeTransparent(backColor);

    // Draw the transparent bitmap to the screen.
    e.Graphics.DrawImage(
        myBitmap, myBitmap.Width, 0, myBitmap.Width, myBitmap.Height);
}
Private Sub MakeTransparent_Example2(ByVal e As PaintEventArgs)

    ' Create a Bitmap object from an image file.
    Dim myBitmap As New Bitmap("Grapes.gif")

    ' Draw myBitmap to the screen.
    e.Graphics.DrawImage(myBitmap, 0, 0, myBitmap.Width, _
        myBitmap.Height)

    ' Get the color of a background pixel.
    Dim backColor As Color = myBitmap.GetPixel(1, 1)

    ' Make backColor transparent for myBitmap.
    myBitmap.MakeTransparent(backColor)

    ' Draw the transparent bitmap to the screen.
    e.Graphics.DrawImage(myBitmap, myBitmap.Width, 0, myBitmap.Width, _
        myBitmap.Height)
End Sub

Comentários

Quando você chamar MakeTransparent, o bitmap será convertido no Format32bppArgb formato , pois esse formato dá suporte a um canal alfa.

Aplica-se a