Udostępnij za pośrednictwem


Bitmap.MakeTransparent Metoda

Definicja

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

Przeciążenia

MakeTransparent()

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

MakeTransparent(Color)

Powoduje, że określony kolor jest przezroczysty dla tego Bitmap.

MakeTransparent()

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

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

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

Wyjątki

Format obrazu Bitmap to format ikony.

Operacja nie powiodła się.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z formularzami Systemu Windows i wymaga PaintEventArgse, który jest parametrem programu obsługi zdarzeń Paint. Kod sprawia, że system jest domyślny przezroczysty kolor przezroczysty dla myBitmap, a następnie rysuje Bitmap 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 powoduje, że domyślny kolor przezroczysty dla tego Bitmap. Jeśli system nie określi przezroczystego koloru, LightGray jest przezroczystym kolorem.

Podczas wywoływania MakeTransparentmapa bitowa zostanie przekonwertowana na format Format32bppArgb, 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
Źródło:
Bitmap.cs
Źródło:
Bitmap.cs

Powoduje, że określony kolor jest przezroczysty dla tego 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)

Parametry

transparentColor
Color

Struktura Color, która reprezentuje kolor, aby uczynić go przezroczystym.

Wyjątki

Format obrazu Bitmap to format ikony.

Operacja nie powiodła się.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z formularzami Systemu Windows i wymaga PaintEventArgse, który jest parametrem programu obsługi zdarzeń Paint. Kod wykonuje następujące akcje:

  • Pobiera kolor piksela w Bitmap.

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

  • Rysuje Bitmap na ekranie.

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

Podczas wywoływania MakeTransparentmapa bitowa zostanie przekonwertowana na format Format32bppArgb, ponieważ ten format obsługuje kanał alfa.

Dotyczy