Bitmap.MakeTransparent Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
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 myBitmap
y, 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
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
Comentarios
https://aka.ms/ContentUserFeedback.
Próximamente: A lo largo de 2024 iremos eliminando gradualmente GitHub Issues como mecanismo de comentarios sobre el contenido y lo sustituiremos por un nuevo sistema de comentarios. Para más información, vea:Enviar y ver comentarios de