Thursday, 1 July 2010

How to make bmp Transparent

So, lets say you are trying to draw a button dynamically using System.Drawing. You pull in the corners from an existing png file but the corner edges are white, so when overlaying they look funny.
Here is what we do:

  1. Bitmap bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);
  2. Bitmap left = new Bitmap(Server.MapPath("~/custom/controls/button/btn_tall_off_left.png"));
  3. left.MakeTransparent(Color.White);
The color you want to make transparent in the png is what you pass into the MakeTransparent() method.

No comments:

Post a Comment