Export (0) Print
Expand All

Bitmap.MakeTransparent Method

Makes the default transparent color transparent for this Bitmap.

Overload List

Makes the default transparent color transparent for this Bitmap object.

[Visual Basic] Overloads Public Sub MakeTransparent()
[C#] public void MakeTransparent();
[C++] public: void MakeTransparent();
[JScript] public function MakeTransparent();

Makes the specified color transparent for this Bitmap object.

[Visual Basic] Overloads Public Sub MakeTransparent(Color)
[C#] public void MakeTransparent(Color);
[C++] public: void MakeTransparent(Color);
[JScript] public function MakeTransparent(Color);

Example

[Visual Basic, C#] The following example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Gets the color of a pixel in a Bitmap object.
  • Makes that color transparent for the bitmap.
  • Draws the Bitmap object to the screen.
[Visual Basic, C#] Note   This example shows how to use one of the overloaded versions of MakeTransparent. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
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] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Bitmap Class | Bitmap Members | System.Drawing Namespace

Show:
© 2015 Microsoft