Bitmap.MakeTransparent Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Macht die standardmäßige transparente Farbe für diese Bitmap transparent.
Überlädt
MakeTransparent() |
Macht die standardmäßige transparente Farbe für diese Bitmap transparent. |
MakeTransparent(Color) |
Bewirkt, dass die angegebene Farbe für diese Bitmap transparent wird. |
MakeTransparent()
- Quelle:
- Bitmap.cs
- Quelle:
- Bitmap.cs
- Quelle:
- Bitmap.cs
Macht die standardmäßige transparente Farbe für diese Bitmap transparent.
public:
void MakeTransparent();
public void MakeTransparent ();
member this.MakeTransparent : unit -> unit
Public Sub MakeTransparent ()
Ausnahmen
Das Bildformat der Bitmap ist ein Symbolformat.
Fehler beim Vorgang.
Beispiele
Das folgende Codebeispiel ist für die Verwendung mit Windows Forms konzipiert und erfordert PaintEventArgse
, was ein Parameter des Paint Ereignishandlers ist. Der Code macht die standardtransparente Systemfarbe transparent für myBitmap
und zeichnet dann auf Bitmap den Bildschirm.
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 Alphafarbe. Mit dieser Methode wird die standardmäßige transparente Farbe für diese Bitmaptransparent. Wenn vom System keine transparente Farbe angegeben wird, LightGray ist 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
Bewirkt, dass die angegebene Farbe für diese Bitmap transparent wird.
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
Ausnahmen
Das Bildformat der Bitmap ist ein Symbolformat.
Fehler beim Vorgang.
Beispiele
Das folgende Codebeispiel ist für die Verwendung mit Windows Forms konzipiert und erfordert PaintEventArgse
, was ein Parameter des Paint Ereignishandlers ist. Der Code führt die folgenden Aktionen aus:
Ruft die Farbe eines Pixels in einem ab Bitmap.
Macht diese Farbe für die Bitmap transparent.
Zeichnet den Bitmap auf den 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:
Feedback
https://aka.ms/ContentUserFeedback.
Bald verfügbar: Im Laufe des Jahres 2024 werden wir GitHub-Issues stufenweise als Feedbackmechanismus für Inhalte abbauen und durch ein neues Feedbacksystem ersetzen. Weitere Informationen finden Sie unterFeedback senden und anzeigen für