[IADP] 介紹 ImageConvert 程式

  • 2614
  • 0

[IADP] 介紹 ImageConvert 程式

這個是我一支 Intel AppUp 程式做一個圖片大小及格式轉換小工具。

程式重點如下:

private void button2_Click(object sender, EventArgs e)
      {
          if (img == null)
          {
              MessageBox.Show("Please select the source image file?");
              return;
          }
          saveFileDialog1.Title = "Save Image File";

          saveFileDialog1.Filter = "Bitmap Files|*.bmp" +

              "|Enhanced Windows MetaFile|*.emf" +

              "|Exchangeable Image File|*.exif" +

              "|Gif Files|*.gif|Icons|*.ico|JPEG Files|*.jpg" +

              "|PNG Files|*.png|TIFF Files|*.tif|Windows MetaFile|*.wmf";

          saveFileDialog1.DefaultExt = "bmp";

          saveFileDialog1.FilterIndex = 1;

          saveFileDialog1.FileName = "";

          if (saveFileDialog1.ShowDialog() == DialogResult.OK)
          {
              if (saveFileDialog1.FileName.Length > 0)
              {
                  Image result = Resize(img, Convert.ToInt32(txtW.Text), Convert.ToInt32(txtH.Text));
                  result.Save(saveFileDialog1.FileName);
                   MessageBox.Show("Successful conversion");
              }
          }
      }
      public Image Resize(Image img, int NewW,int NewH)
      {
           Bitmap bmp = new Bitmap(NewW, NewH);
          Graphics graphic = Graphics.FromImage((Image)bmp);
          graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
          graphic.DrawImage(img, 0, 0, resizedW, resizedH);
         graphic.Dispose();
          return (Image)bmp;

     }

執行畫面如下:

ooo

剛發行上去不知道會不會過

Untitled