Share via


Bitmap.MakeTransparent Metoda

Definice

Nastaví výchozí průhlednou barvu pro tuto Bitmap.

Přetížení

MakeTransparent()

Nastaví výchozí průhlednou barvu pro tuto Bitmap.

MakeTransparent(Color)

Nastaví zadanou barvu průhlednou pro tuto Bitmap.

MakeTransparent()

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Nastaví výchozí průhlednou barvu pro tuto Bitmap.

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

Výjimky

Formát obrázku Bitmap je formát ikony.

Operace se nezdařila.

Příklady

Následující příklad kódu je určen pro použití s model Windows Forms a vyžaduje PaintEventArgse, což je parametr obslužné rutiny Paint události. Kód nastaví výchozí průhlednou barvu systému pro myBitmapa pak nakreslí Bitmap na obrazovku.

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

Poznámky

Systémová paleta definuje jednu barvu jako výchozí průhlednou nebo alfa barvu. Tato metoda zprůhlední výchozí průhlednou barvu pro tento Bitmap. Pokud systém nezadá žádnou průhlednou barvu, LightGray je průhledná barva.

Při volání MakeTransparentse rastrový obrázek převede do Format32bppArgb formátu, protože podporuje alfa kanál.

Platí pro

MakeTransparent(Color)

Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs
Zdroj:
Bitmap.cs

Nastaví zadanou barvu průhlednou pro tuto 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 představující barvu, která má být průhledná.

Výjimky

Formát obrázku Bitmap je formát ikony.

Operace se nezdařila.

Příklady

Následující příklad kódu je určen pro použití s model Windows Forms a vyžaduje PaintEventArgse, což je parametr obslužné rutiny Paint události. Kód provede následující akce:

  • Získá barvu pixelu v objektu Bitmap.

  • Zprůhlední tuto barvu rastrového obrázku.

  • Nakreslí na Bitmap obrazovku.

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

Poznámky

Při volání MakeTransparentse rastrový obrázek převede do Format32bppArgb formátu, protože podporuje alfa kanál.

Platí pro