Aracılığıyla paylaş


Bitmap.MakeTransparent Yöntem

Tanım

Bu Bitmapiçin varsayılan saydam rengi saydam yapar.

Aşırı Yüklemeler

MakeTransparent()

Bu Bitmapiçin varsayılan saydam rengi saydam yapar.

MakeTransparent(Color)

Bu Bitmapiçin belirtilen rengi saydam hale getirir.

MakeTransparent()

Kaynak:
Bitmap.cs
Kaynak:
Bitmap.cs
Kaynak:
Bitmap.cs

Bu Bitmapiçin varsayılan saydam rengi saydam yapar.

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

Özel durumlar

öğesinin Bitmap görüntü biçimi bir simge biçimidir.

İşlem başarısız oldu.

Örnekler

Aşağıdaki kod örneği, Windows Forms ile kullanılmak üzere tasarlanmıştır ve olay işleyicisinin bir parametresi olan öğesini gerektirirPaintEventArgse.Paint Kod, için sistemin varsayılan saydam rengini saydam myBitmaphale getirir ve ardından öğesini ekrana çizer 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

Açıklamalar

Sistem paleti bir rengi varsayılan saydam veya alfa rengi olarak tanımlar. Bu yöntem, bu Bitmapiçin varsayılan saydam rengi saydam hale getirir. Sistem tarafından saydam renk belirtilmezse, LightGray saydam renktir.

çağırdığınızda MakeTransparentbit eşlem biçime Format32bppArgb dönüştürülür, bu biçim bir alfa kanalını destekler.

Şunlara uygulanır

MakeTransparent(Color)

Kaynak:
Bitmap.cs
Kaynak:
Bitmap.cs
Kaynak:
Bitmap.cs

Bu Bitmapiçin belirtilen rengi saydam hale getirir.

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)

Parametreler

transparentColor
Color

Saydam Color hale getirmek için rengi temsil eden yapı.

Özel durumlar

öğesinin Bitmap görüntü biçimi bir simge biçimidir.

İşlem başarısız oldu.

Örnekler

Aşağıdaki kod örneği, Windows Forms ile kullanılmak üzere tasarlanmıştır ve olay işleyicisinin bir parametresi olan öğesini gerektirirPaintEventArgse.Paint Kod aşağıdaki eylemleri gerçekleştirir:

  • bir pikselin Bitmaprengini alır.

  • Bu rengi bit eşlem için saydam hale getirir.

  • ekranı çizer 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

Açıklamalar

çağırdığınızda MakeTransparentbit eşlem biçime Format32bppArgb dönüştürülür, bu biçim bir alfa kanalını destekler.

Şunlara uygulanır