基本信息
源码名称:gif图片转换成jpg文件格式 实例源码
源码大小:0.01M
文件格式:.zip
开发语言:C#
更新时间:2013-05-22
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍



    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 = "*.gif|*.gif|*.jpg|*.jpg;";
            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;//获取另存为文件的路径及名称
                    if (comboBox.SelectedIndex == 0)//如果选择了第一项
                        bitmap.Save(fileName, ImageFormat.Gif);//调用Save方法将图片保存为gif格式
                    else if (comboBox.SelectedIndex == 1)//如果选择了第二项
                        bitmap.Save(fileName, ImageFormat.Jpeg);//调用Save方法将图片保存为jpg格式
                    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();
        }

        private void Frm_Main_Load(object sender, EventArgs e)
        {
            comboBox.SelectedIndex = 0;
        }
    }