C# Convert an .Ico File to a .Bmp

C# Convert an .Ico File to a .Bmp



In this example, using the Bitmap class included in the System.Drawing namespace, an .ico file is converted to a .bmp file to display it in a PictureBox.
This is necessary because the .ico format is not supported by the PictureBox control.
using System.Drawing;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Bitmap FromIconToBitmap(Icon icon)
{
Bitmap bmp = new Bitmap(icon.Width, icon.Height);
using (Graphics gp = Graphics.FromImage(bmp))
{
gp.Clear(
Color.Transparent);
gp.DrawIcon(icon,
new Rectangle(0, 0, icon.Width, icon.Height));
}
return bmp;
}
 
private void Button1_Click(System.Object sender, System.EventArgs e)
{
Icon icon = WindowsFormsApplication1.Properties.Resources.Icon1;
pictureBox1.Image = FromIconToBitmap(icon);
}
}
}
Leave a Comment
  • Please add 3 and 5 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Comments
  • Richard Mueller edited Revision 1. Comment: Removed (en-US) from title, modified title, added tag, improved grammar

Page 1 of 1 (1 items)
Wikis - Comment List
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Richard Mueller edited Revision 1. Comment: Removed (en-US) from title, modified title, added tag, improved grammar

Page 1 of 1 (1 items)