zoukankan      html  css  js  c++  java
  • 图形技术(BMP转换成JPG格式)

    记忆是有限的,你们应该知道我想说什么了。

     //核心代码

    Bitmap bitmap;

     private void buttonOpen_Click(object sender, EventArgs e)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = "*.bmp|*.bmp";
                openFileDialog.Title = "打开图像文件";
                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.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.Jpeg);
                      /*  FileInfo f = new FileInfo(fileName);
                        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();
            }

  • 相关阅读:
    USACO2.3.3Zero Sum
    微信公众平台消息接口开发(8)小黄鸡(小贱鸡)机器人
    微信群二维码
    PHP正则表达式入门教程[转]
    微信公众平台消息接口开发(23)图片识别之男人味/女人味指数
    微信公众平台消息接口开发(50)在线点歌/在线音乐
    微信公众平台消息接口开发(21)图片识别之亲子鉴定
    微信公众平台消息接口开发(4)天气预报
    微信公众平台消息接口开发(5)股票查询
    微信公众平台消息接口开发(40)语音识别
  • 原文地址:https://www.cnblogs.com/msAspnet/p/2097293.html
Copyright © 2011-2022 走看看