iT邦幫忙

DAY 12
3

程式隨手寫系列 第 12

小功能(9)

  • 分享至 

  • xImage
  •  
 Bitmap bitmap;
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openfile = new OpenFileDialog();
            openfile.Filter = "*.bmp|*.bmp";
            openfile.Title = "open 文件";
            openfile.Multiselect = false;
            if (openfile.ShowDialog()==DialogResult.OK)
            {
                if (bitmap != null)
                    bitmap.Dispose();
                string fileName = openfile.FileName;
                bitmap = new Bitmap(fileName);
                if (bitmap.Width>bitmap.Height)
                {
                    pictureBox1.Width = panel1.Width;
                    pictureBox1.Height = (int)((double)bitmap.Height * panel1.Width / bitmap.Width);
                }
                else
                {
                    pictureBox1.Height = panel1.Height;
                    pictureBox1.Width = (int)((double)bitmap.Width * panel1.Height / bitmap.Height);
                }
                pictureBox1.Image = bitmap;
                FileInfo f = new FileInfo(fileName);
                this.Text = "圖像轉換" + f.Name;
                button2.Enabled = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem==null)
            {
                return;
            }
            else
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Title = "轉化為: ";
                saveFileDialog.OverwritePrompt = true;
                saveFileDialog.CheckPathExists = true;
                saveFileDialog.Filter = comboBox1.Text + "|" + comboBox1.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;
                }
            }
        }

圖像轉換


上一篇
小功能(8)
下一篇
小功能(10)
系列文
程式隨手寫20
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0

我要留言

立即登入留言