Bitmap.MakeTransparent Método

Definición

Hace que el color predeterminado sea transparente en este Bitmap.

Sobrecargas

MakeTransparent()

Hace que el color predeterminado sea transparente en este Bitmap.

MakeTransparent(Color)

Hace que el color especificado sea transparente para este objeto Bitmap.

MakeTransparent()

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs

Hace que el color predeterminado sea transparente en este Bitmap.

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

Excepciones

El formato de imagen de Bitmap es un formato de icono.

Error en la operación.

Ejemplos

El ejemplo de código siguiente está diseñado para su uso con Windows Forms y requiere PaintEventArgse, que es un parámetro del Paint controlador de eventos. El código hace que el color transparente predeterminado del sistema sea transparente para myBitmapy, a continuación, dibuja en Bitmap la pantalla.

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

Comentarios

La paleta del sistema define un color como el color transparente predeterminado, o alfa. Este método hace que el color transparente predeterminado sea transparente para este Bitmap. Si el sistema no especifica ningún color transparente, LightGray es el color transparente.

Al llamar a MakeTransparent, el mapa de bits se convertirá al Format32bppArgb formato , ya que este formato admite un canal alfa.

Se aplica a

MakeTransparent(Color)

Source:
Bitmap.cs
Source:
Bitmap.cs
Source:
Bitmap.cs

Hace que el color especificado sea transparente para este objeto 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

Estructura Color que representa el color que se va a hacer transparente.

Excepciones

El formato de imagen de Bitmap es un formato de icono.

Error en la operación.

Ejemplos

El ejemplo de código siguiente está diseñado para su uso con Windows Forms y requiere PaintEventArgse, que es un parámetro del Paint controlador de eventos. El código realiza las siguientes acciones:

  • Obtiene el color de un píxel en un objeto Bitmap.

  • Hace que ese color sea transparente para el mapa de bits.

  • Dibuja en Bitmap la pantalla.

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

Comentarios

Al llamar a MakeTransparent, el mapa de bits se convertirá al Format32bppArgb formato , ya que este formato admite un canal alfa.

Se aplica a