Make ico files from png


I found this great freeware utility, png2ico, which will take a png and create an ico file. I wanted to create a favicon for my web site, and this made it super simple.


This will also come in handy when I need to make icons for my .NET applications. the VS.NET 2003 editor can’t handle 32 bit icons.

Comments (3)

  1. Jon Galloway says:

    I like this better:

    http://www.chami.com/html-kit/services/favicon/

    Nothing to download or install, and it works with several image formats.

  2. Jeff Parker says:

    You know I made an Icon creator in .net I do not have access to the full code right handy, but here is or what my preliminary testing scratch pad code. But anyway it takes ANY image format and creates an icon for it and then sets it to the icon of the form. You just need to modify it to save it back out. It is really pretty simple code using .net to create an Icon. Lot of hard coded values I made the final one a lot more Dynamic like I say this was my scratch pad and not a lot of comments. But you might want to give it a try and create your own in .net.

    using System;

    using System.ComponentModel;

    using System.Drawing;

    using System.Drawing.Drawing2D;

    using System.Drawing.Imaging;

    using System.Windows.Forms;

    namespace IconCreator

    {

    /// <summary>

    /// Summary description for Form1.

    /// </summary>

    public class Form1 : Form

    {

    private Image originalFile;

    private Icon iconFile;

    private Button button1;

    private OpenFileDialog openFileDialog1;

    private SaveFileDialog saveFileDialog1;

    private GroupBox groupBox1;

    private GroupBox groupBox2;

    private PictureBox pictureBox1;

    private PictureBox pictureBox2;

    /// <summary>

    /// Required designer variable.

    /// </summary>

    private Container components = null;

    public Form1()

    {

    InitializeComponent();

    }

    protected override void Dispose( bool disposing )

    {

    if( disposing )

    {

    if (components != null)

    {

    components.Dispose();

    }

    }

    base.Dispose( disposing );

    }

    #region Windows Form Designer generated code

    /// <summary>

    /// Required method for Designer support – do not modify

    /// the contents of this method with the code editor.

    /// </summary>

    private void InitializeComponent()

    {

    this.button1 = new System.Windows.Forms.Button();

    this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();

    this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();

    this.groupBox1 = new System.Windows.Forms.GroupBox();

    this.groupBox2 = new System.Windows.Forms.GroupBox();

    this.pictureBox1 = new System.Windows.Forms.PictureBox();

    this.pictureBox2 = new System.Windows.Forms.PictureBox();

    this.groupBox1.SuspendLayout();

    this.groupBox2.SuspendLayout();

    this.SuspendLayout();

    //

    // button1

    //

    this.button1.Location = new System.Drawing.Point(424, 0);

    this.button1.Name = "button1";

    this.button1.Size = new System.Drawing.Size(160, 23);

    this.button1.TabIndex = 0;

    this.button1.Text = "button1";

    this.button1.Click += new System.EventHandler(this.button1_Click);

    //

    // groupBox1

    //

    this.groupBox1.Controls.Add(this.pictureBox1);

    this.groupBox1.Location = new System.Drawing.Point(8, 8);

    this.groupBox1.Name = "groupBox1";

    this.groupBox1.Size = new System.Drawing.Size(408, 224);

    this.groupBox1.TabIndex = 1;

    this.groupBox1.TabStop = false;

    this.groupBox1.Text = "Original Image";

    //

    // groupBox2

    //

    this.groupBox2.Controls.Add(this.pictureBox2);

    this.groupBox2.Location = new System.Drawing.Point(8, 240);

    this.groupBox2.Name = "groupBox2";

    this.groupBox2.Size = new System.Drawing.Size(408, 160);

    this.groupBox2.TabIndex = 2;

    this.groupBox2.TabStop = false;

    this.groupBox2.Text = "Icon";

    //

    // pictureBox1

    //

    this.pictureBox1.Location = new System.Drawing.Point(8, 16);

    this.pictureBox1.Name = "pictureBox1";

    this.pictureBox1.Size = new System.Drawing.Size(392, 200);

    this.pictureBox1.TabIndex = 0;

    this.pictureBox1.TabStop = false;

    //

    // pictureBox2

    //

    this.pictureBox2.Location = new System.Drawing.Point(8, 16);

    this.pictureBox2.Name = "pictureBox2";

    this.pictureBox2.Size = new System.Drawing.Size(392, 136);

    this.pictureBox2.TabIndex = 0;

    this.pictureBox2.TabStop = false;

    //

    // Form1

    //

    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

    this.ClientSize = new System.Drawing.Size(584, 405);

    this.Controls.Add(this.groupBox2);

    this.Controls.Add(this.groupBox1);

    this.Controls.Add(this.button1);

    this.Name = "Form1";

    this.Text = "Form1";

    this.groupBox1.ResumeLayout(false);

    this.groupBox2.ResumeLayout(false);

    this.ResumeLayout(false);

    }

    #endregion

    /// <summary>

    /// The main entry point for the application.

    /// </summary>

    [STAThread]

    static void Main()

    {

    Application.Run(new Form1());

    }

    private void button1_Click(object sender, EventArgs e)

    {

    this.openFileDialog1.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF";

    this.openFileDialog1.FilterIndex = 1;

    if(openFileDialog1.ShowDialog() == DialogResult.OK)

    {

    originalFile = Image.FromStream(openFileDialog1.OpenFile());

    SetDisplay();

    }

    }

    private void SetDisplay()

    {

    int MaximumTargetWidth = 32;

    int MaximumTargetHeight = 32;

    this.pictureBox1.Image = originalFile;

    int NewWidth = originalFile.Width;

    int NewHeight = originalFile.Height;

    if(MaximumTargetWidth < originalFile.Width || MaximumTargetHeight < originalFile.Height)

    {

    float PercentToReduce;

    if((originalFile.Width – MaximumTargetWidth) >= (originalFile.Height – MaximumTargetHeight))

    {

    NewWidth = MaximumTargetWidth;

    PercentToReduce = ((float)NewWidth / originalFile.Width);

    NewHeight = (int)(originalFile.Height * PercentToReduce);

    }

    else

    {

    NewHeight = MaximumTargetHeight;

    PercentToReduce = ((float)NewHeight / originalFile.Height);

    NewWidth = (int)(originalFile.Width * PercentToReduce);

    }

    }

    Bitmap NewImage = new Bitmap(NewWidth,NewHeight,PixelFormat.Format32bppRgb);

    NewImage.SetResolution(originalFile.HorizontalResolution,originalFile.VerticalResolution);

    Graphics gr = Graphics.FromImage(NewImage);

    gr.SmoothingMode = SmoothingMode.HighQuality;

    gr.DrawImage(originalFile,new Rectangle(0,0,NewWidth,NewHeight),new Rectangle(0,0,originalFile.Width,originalFile.Height),GraphicsUnit.Pixel);

    this.iconFile = Icon.FromHandle(NewImage.GetHicon());

    this.Icon = iconFile;

    }

    }

    }

  3. Jeff Parker says:

    Oh yeah and you need to set change the filter on the open dialog box to include png but it will open them just fine and convert them from png to icon format.