次の方法で共有


Bitmap.MakeTransparent メソッド

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

オーバーロードの一覧

既定の透明色をこの Bitmap オブジェクトに使用します。

[Visual Basic] Overloads Public Sub MakeTransparent()

[C#] public void MakeTransparent();

[C++] public: void MakeTransparent();

[JScript] public function MakeTransparent();

指定の透明色をこの Bitmap オブジェクトに使用します。

[Visual Basic] Overloads Public Sub MakeTransparent(Color)

[C#] public void MakeTransparent(Color);

[C++] public: void MakeTransparent(Color);

[JScript] public function MakeTransparent(Color);

使用例

[Visual Basic, C#] 次の例は、Windows フォームでの使用を意図してデザインされており、 Paint イベント ハンドラのパラメータである PaintEventArgs e が必要です。このコードは次のアクションを実行します。

  • Bitmap オブジェクトのピクセルの色を取得します。
  • その色をビットマップの透明色に使用します。
  • 画面に Bitmap オブジェクトを描画します。

[Visual Basic, C#] メモ   ここでは、MakeTransparent のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Public Sub MakeTransparent_Example(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
        
[C#] 
public void MakeTransparent_Example(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);
}
        

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

Bitmap クラス | Bitmap メンバ | System.Drawing 名前空間