Bitmap.MakeTransparent Metoda

Definicja

Powoduje, że domyślny przezroczysty kolor jest przezroczysty dla tego Bitmapelementu .

Przeciążenia

MakeTransparent()

Powoduje, że domyślny przezroczysty kolor jest przezroczysty dla tego Bitmapelementu .

MakeTransparent(Color)

Sprawia, że określony kolor jest przezroczysty dla tego Bitmapelementu .

MakeTransparent()

Źródło:
Bitmap.cs
Źródło:
Bitmap.cs
Źródło:
Bitmap.cs

Powoduje, że domyślny przezroczysty kolor jest przezroczysty dla tego Bitmapelementu .

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

Wyjątki

Format obrazu elementu Bitmap to format ikony.

Operacja nie powiodła się.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgseparametru Paint programu obsługi zdarzeń. Kod sprawia, że system jest domyślny przezroczysty kolor przezroczysty dla myBitmapelementu , a następnie rysuje Bitmap go na ekranie.

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

Uwagi

Paleta systemowa definiuje jeden kolor jako domyślny przezroczysty lub alfa. Ta metoda sprawia, że domyślny przezroczysty kolor jest przezroczysty dla tego elementu Bitmap. Jeśli system nie określi koloru przezroczystego, LightGray jest przezroczystym kolorem.

Gdy wywołasz MakeTransparentmetodę , mapa bitowa zostanie przekonwertowana na Format32bppArgb format, ponieważ ten format obsługuje kanał alfa.

Dotyczy

MakeTransparent(Color)

Źródło:
Bitmap.cs
Źródło:
Bitmap.cs
Źródło:
Bitmap.cs

Sprawia, że określony kolor jest przezroczysty dla tego Bitmapelementu .

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)

Parametry

transparentColor
Color

Struktura Color reprezentująca kolor, który ma być przezroczysty.

Wyjątki

Format obrazu elementu Bitmap to format ikony.

Operacja nie powiodła się.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgseparametru Paint programu obsługi zdarzeń. Kod wykonuje następujące akcje:

  • Pobiera kolor piksela w obiekcie Bitmap.

  • Sprawia, że kolor jest przezroczysty dla mapy bitowej.

  • Rysuje ekran Bitmap .

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

Uwagi

Gdy wywołasz MakeTransparentmetodę , mapa bitowa zostanie przekonwertowana na Format32bppArgb format, ponieważ ten format obsługuje kanał alfa.

Dotyczy