Converting an .Ico File to a .Bmp in C#

  1. using System.Drawing;  
  2. using System.Windows.Forms;  
  3.    
  4. namespace WindowsFormsApplication1  
  5. {  
  6.   public partial class Form1 : Form  
  7.   {  
  8.     public Bitmap FromIconToBitmap(Icon icon)  
  9.     {  
  10.       Bitmap bmp = new Bitmap(icon.Width, icon.Height);  
  11.       using (Graphics gp = Graphics.FromImage(bmp))  
  12.       {  
  13.         gp.Clear(Color.Transparent);  
  14.         gp.DrawIcon(icon, new Rectangle(0, 0, icon.Width, icon.Height));  
  15.       }  
  16.       return bmp;  
  17.     }  
  18.    
  19.     private void Button1_Click(System.Object sender, System.EventArgs e)  
  20.     {  
  21.       Icon icon = WindowsFormsApplication1.Properties.Resources.Icon1;  
  22.       pictureBox1.Image = FromIconToBitmap(icon);  
  23.     }  
  24.   }  
  25. }