首页

c# Ico图片文件转换成 bmp格式 实例源码

c#

2020-8-29

    public partial class Frm_Main : Form
    {
        Bitmap bitmap;
        public Frm_Main()
        {
            InitializeComponent();
        }

        private void buttonOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "*.ico|*.ico";
            openFileDialog.Title = "打开ICO文件";
            openFileDialog.Multiselect = false;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }
                string fileName = openFileDialog.FileName;
                bitmap = new Bitmap(fileName);
                if (bitmap.Width > bitmap.Height)
                {
                    pictureBox.Width = panel2.Width;
                    pictureBox.Height = (int)((double)bitmap.Height * panel2.Width / bitmap.Width);
                }
                else
                {
                    pictureBox.Height = panel2.Height;
                    pictureBox.Width = (int)((double)bitmap.Width * panel2.Height / bitmap.Height);
                }
                pictureBox.Image = bitmap;
                FileInfo f = new FileInfo(fileName);
                this.Text = "图像转换:"   f.Name;
                this.label1.Text = f.Name;
                buttonConvert.Enabled = true;
            }
        }

        private void buttonConvert_Click(object sender, EventArgs e)
        {
            if (comboBox.SelectedItem == null) 							//如果没有选定项
            {
                return; 												//退出本次操作
            }
            else
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog(); 			//实例化SaveFileDialog类
                saveFileDialog.Title = "转化为:"; 							//设置“另存为”对话框的题标
                saveFileDialog.OverwritePrompt = true; 						//如果文件名存在则提示
                saveFileDialog.CheckPathExists = true; 						//如果文件的路径不存在则提示
                saveFileDialog.Filter = comboBox.Text   "|"   comboBox.Text; 		//设置文件类型
                if (saveFileDialog.ShowDialog() == DialogResult.OK) 			//打开“另存为”对话框
                {
                    string fileName = saveFileDialog.FileName; 				//获取另存为文件的路径及名称
                    bitmap.Save(fileName, ImageFormat.Bmp); 				//调用Save方法将图片保存为bmp格式
                    FileInfo f = new FileInfo(fileName); 						//实例化FileInfo类
                    this.Text = "图像转换:"   f.Name;	 					//设置窗体标题栏
                    label1.Text = f.Name;
                }
            }
        }

        private void panel2_Resize(object sender, EventArgs e)
        {
            pictureBox.Top = panel1.Top;
            pictureBox.Left = panel1.Left;
            if (bitmap != null)
            {
                if (bitmap.Width > bitmap.Height)
                {
                    pictureBox.Width = panel2.Width;
                    pictureBox.Height = (int)((double)bitmap.Height * panel2.Width / bitmap.Width);
                }
                else
                {
                    pictureBox.Height = panel2.Height;
                    pictureBox.Width = (int)((double)bitmap.Width * panel2.Height / bitmap.Height);
                }
            }
            else
            {
                pictureBox.Width = panel2.Width;
                pictureBox.Height = panel2.Height;
            }
            pictureBox.Refresh();
        }
    }
资源下载此资源下载价格为2D币(VIP免费),请先
资源文件列表
ICOChangeBMP.sln , 926
ICOChangeBMP.suo , 19968
ICOChangeBMP/Frm_Main.cs , 4056
ICOChangeBMP/Frm_Main.designer.cs , 7119
ICOChangeBMP/Frm_Main.resx , 5814
ICOChangeBMP/ICOChangeBMP.csproj , 3839
ICOChangeBMP/obj/Debug/ICOChangeBMP.csproj.FileListAbsolute.txt , 2236
ICOChangeBMP/Program.cs , 496
ICOChangeBMP/Properties/AssemblyInfo.cs , 1356
ICOChangeBMP/Properties/Resources.Designer.cs , 2874
ICOChangeBMP/Properties/Resources.resx , 5612
ICOChangeBMP/Properties/Settings.Designer.cs , 1097
ICOChangeBMP/Properties/Settings.settings , 249
没有账号? 忘记密码?

社交账号快速登录