ICO图标生成器

工具主要使用的方法是Image 类的 GetThumbnailImage(int thumbWidth, int thumbHeight, System.Drawing.Image.GetThumbnailImageAbort callback, IntPtr callbackData)方法,具体方法解释可以百度了解,我采用的方法是定义一个全局的Bitmap 用来保存 OpenFileDialog保存选取的图片文件。

1.选取图像

private void btn_OpenPic_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "图像文件|*.JPG;*.JPEG;*.PNG";
            if (open.ShowDialog() == DialogResult.OK)
            {
                bitmap = new Bitmap(open.FileName);
            }
        }

2.调整导出的ICO大小

private void ChangePicSize()
        {
            if (bitmap == null)
            {
                return;
            }
            Image img = null;
            switch (this.cbo_Type.Text)
            {
                case "16 * 16":
                    img = bitmap.GetThumbnailImage(16, 16, null, IntPtr.Zero);
                    break;
                case "32 * 32":
                    img = bitmap.GetThumbnailImage(32, 32, null, IntPtr.Zero);
                    break;
                case "48 * 48":
                    img = bitmap.GetThumbnailImage(48, 48, null, IntPtr.Zero);
                    break;
                case "64 * 64":
                    img = bitmap.GetThumbnailImage(64, 64, null, IntPtr.Zero);
                    break;
                case "128 * 128":
                    img = bitmap.GetThumbnailImage(128, 128, null, IntPtr.Zero);
                    break;
                default:
                    break;
            }
            this.pic_Preview.Image = img;
        }

3.导出

 private void btn_DownLoad_Click(object sender, EventArgs e)
        {
            if (bitmap == null)
            {
                return;
            }
            SaveFileDialog sa = new SaveFileDialog();
            sa.Filter = "(图标文件)|*.ico";
            if (sa.ShowDialog() == DialogResult.OK)
            {
                Image img = this.pic_Preview.Image;
                img.Save(sa.FileName);
                MessageBox.Show("下载完成,感谢使用");
            }
        }

完整代码VS2015编写

你可能感兴趣的:(ICO)