Converting a Bitmap to Have a Transparent Background

Environment: .NET Beta 2

This article tells you how to make a bitmap of a picturebox with transparent background

If you search for a transparent method in the picturebox clas, you will see that the method do not exist. So there must be another way to make the background of a bitmap transparent. Have a look in the bitmap class and you will find a transparent method “MakeTransparent”. You must first convert your image to a bitmap and then select the background (transparent) color. After that, make the background color transparent and finally convert it back to the image of the control.

Example code:

1) Convert your image to a bitmap

Bitmap Logo = new Bitmap(CompanyLogo.Image);

2) select the background color (here the left top pixel) and make it transparent

Logo.MakeTransparent(Logo.GetPixel(1, 1));

3) Finally convert it back to the image

CompanyLogo.Image = (Image) Logo;

That’s all

More by Author

Previous article
Next article

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read