Bitmap.MakeTransparent Methode

Definition

Macht die standardtransparente Farbe transparent für dieses Bitmap.

Überlädt

Name Beschreibung
MakeTransparent()

Macht die standardtransparente Farbe transparent für dieses Bitmap.

MakeTransparent(Color)

Macht die angegebene Farbe für diese BitmapFarbe transparent.

MakeTransparent()

Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs

Macht die standardtransparente Farbe transparent für dieses Bitmap.

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

Ausnahmen

Das Bildformat des Elements Bitmap ist ein Symbolformat.

Dieser Vorgang ist fehlgeschlagen.

Beispiele

Das folgende Codebeispiel wurde für die Verwendung mit Windows Forms entwickelt und erfordert PaintEventArgse, bei dem es sich um einen Parameter des ereignishandlers Paint handelt. Mit dem Code wird die standardtransparente Farbe des Systems transparent für myBitmapden Bildschirm und dann auf den Bildschirm gefärbt Bitmap .

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

Hinweise

Die Systempalette definiert eine Farbe als standardtransparente oder alphafarbene Farbe. Mit dieser Methode wird die transparente Standardfarbe für diese BitmapMethode transparent. Wenn vom System keine transparente Farbe angegeben wird, LightGray handelt es sich um die transparente Farbe.

Wenn Sie aufrufen MakeTransparent, wird die Bitmap in das Format32bppArgb Format konvertiert, da dieses Format einen Alphakanal unterstützt.

Gilt für:

MakeTransparent(Color)

Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs
Quelle:
Bitmap.cs

Macht die angegebene Farbe für diese BitmapFarbe transparent.

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)

Parameter

transparentColor
Color

Die Color Struktur, die die Farbe darstellt, um transparent zu machen.

Ausnahmen

Das Bildformat des Elements Bitmap ist ein Symbolformat.

Dieser Vorgang ist fehlgeschlagen.

Beispiele

Das folgende Codebeispiel wurde für die Verwendung mit Windows Forms entwickelt und erfordert PaintEventArgse, bei dem es sich um einen Parameter des ereignishandlers Paint handelt. Der Code führt die folgenden Aktionen aus:

  • Ruft die Farbe eines Pixels in einem Bitmap.

  • Macht diese Farbe für die Bitmap transparent.

  • Zeichnet den Bitmap Bildschirm.

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

Hinweise

Wenn Sie aufrufen MakeTransparent, wird die Bitmap in das Format32bppArgb Format konvertiert, da dieses Format einen Alphakanal unterstützt.

Gilt für: