我的任务是调整多个图像的大小。我试过这段代码:
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 :(得分: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
}
}
}