-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);

            }
        }
    }
}
4

1 回答 1

1

好的,所以您正在使用 winforms 并想要打开多个文件?还是目录?并想调整它们的大小。但没有调整大小?还是我需要更多的咖啡?使用http://nuget.org/packages/ImageResizer/我没有看到循环遍历要调整大小的文件。

在此处阅读有关 imageresizer 组件的更多信息:http: //imageresizing.net/docs/managed

在您的 button1 点击事件中,执行以下操作:

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
        }
    }
}
于 2013-07-08T08:47:24.877 回答