2013-07-08 44 views
-3

我的任務是調整多個圖像的大小。我試過這個代碼:如何調整多個圖像的大小

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using System.IO; 

namespace Boyutlandir 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 
     string dosyaYolu = string.Empty; 
     Bitmap bmp = null; 
     OpenFileDialog openFileDialogDosyaAc = new OpenFileDialog(); 

     private void button1_Click(object sender, EventArgs e) 
     { 

      openFileDialogDosyaAc.Multiselect = true; 
      if (openFileDialogDosyaAc.ShowDialog() == DialogResult.OK) 
      { 
       dosyaYolu = openFileDialogDosyaAc.FileName; 

       bmp = new Bitmap(openFileDialogDosyaAc.FileNames.ToString()); 

       pictureBox1.Image = bmp; 

       pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; 
      } 

     } 

     private void button2_Click(object sender, EventArgs e) 
     { 
      Bitmap bmpKucuk = new Bitmap(pictureBox1.Image,Convert.ToInt32(textBox1.Text),Convert.ToInt32(textBox2.Text)); 
      pictureBox1.Image = bmpKucuk; 
      pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; 

     } 

     private void button3_Click(object sender, EventArgs e) 
     { 
      SaveFileDialog sfd = new SaveFileDialog(); 
      sfd.Filter = "jpeg dosyası(*.jpg)|*.jpg|Bitmap(*.bmp)|*.bmp"; 
      DialogResult sonuc = sfd.ShowDialog(); 
      if (sonuc == DialogResult.OK) 
      { 
       pictureBox1.Image.Save(sfd.FileName); 

      } 
     } 
    } 
} 
+0

兩降投票沒有一個單一的評論:-) –

+0

Dowvoters應至少一個評論來證明他們的投票 –

+0

你試過的代碼有什麼問題?請注意,這個問題看起來像「請爲我寫程序」的請求,不受社區歡迎。 (我並不是這個問題的迴歸者)。 – Artemix

回答

1

好的,所以你使用winforms,並希望打開多個文件?或一個目錄?並想調整它們。但沒有調整大小?還是需要更多的咖啡?使用http://nuget.org/packages/ImageResizer/,我沒有看到一個循環來遍歷你想調整大小的文件。

瞭解更多關於imageresizer組件在這裏:http://imageresizing.net/docs/managed

在Button1的Click事件

,做這樣的事情:

private void button1_Click(object sender, EventArgs e) 
{ 
    DialogResult dr = this.openFileDialogDosyaAc.ShowDialog(); 
    if (dr == System.Windows.Forms.DialogResult.OK) 
    { 
     // Read the files 
     foreach (String file in openFileDialogDosyaAc.FileNames) 
     { 
      //resize and save 
     } 
    } 
} 
+1

你應該處置你的ShowDialog()(使用使用) – Sayse

+0

Like Sayse說,也使用這個http://stackoverflow.com/questions/8624654/which-is-a-better-way-to-call-form-showdialog –