Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Bitmap.MakeTransparent Method (Color)

.NET Framework 1.1

Makes the specified color transparent for this Bitmap object.

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

Parameters

transparentColor
The Color structure that represents the color to make transparent.

Return Value

This method does not return a value.

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] 
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.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Bitmap Class | Bitmap Members | System.Drawing Namespace | Bitmap.MakeTransparent Overload List

Show:
© 2015 Microsoft