How to create a transparent Bitmap?

The Bitmap class is having a method named MakeTransparent which takes the color as argument.

Example: Create a new windows form application and keep two PictureBox control on it.  Set the image of PictureBox1 to the following image:

image

 

// Here the color at pixel 1, 1 is made as transparent

Bitmap bitmap = new Bitmap(pictureBox1.Image);

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

 

pictureBox2.Image = bitmap;

On invoking the above code you can see:

image

Leave a Reply

Your email address will not be published. Required fields are marked *