Bitmap.MakeTransparent メソッド

定義

既定の透明色をこの Bitmap で透明します。

オーバーロード

MakeTransparent()

既定の透明色をこの Bitmap で透明します。

MakeTransparent(Color)

指定の透明色をこの Bitmap に使用します。

MakeTransparent()

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

既定の透明色をこの Bitmap で透明します。

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

例外

Bitmap のイメージ形式はアイコン形式です。

操作が失敗しました。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 このコードでは、 に対してシステムの既定の透明色が myBitmap透明になり、 が 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

注釈

システム パレットは、1 つの色を既定の透明色 (アルファ) として定義します。 このメソッドは、この Bitmapの既定の透明色を透明にします。 システムで透明な色が指定されていない場合、 LightGray は透明色です。

を呼び出 MakeTransparentすと、ビットマップはアルファ チャネルを Format32bppArgb サポートするため、形式に変換されます。

適用対象

MakeTransparent(Color)

ソース:
Bitmap.cs
ソース:
Bitmap.cs
ソース:
Bitmap.cs

指定の透明色をこの 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)

パラメーター

transparentColor
Color

透明にする色を表す Color 構造体。

例外

Bitmap のイメージ形式はアイコン形式です。

操作が失敗しました。

次のコード例は、Windows フォームで使用するように設計されており、イベント ハンドラーのPaintパラメーターである が必要PaintEventArgseです。 コードは、次のアクションを実行します。

  • 内のピクセルの色を Bitmap取得します。

  • ビットマップの色を透明にします。

  • 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

注釈

を呼び出 MakeTransparentすと、ビットマップはアルファ チャネルを Format32bppArgb サポートするため、形式に変換されます。

適用対象