C# 如何调整多个图像的大小
我的任务是调整多个图像的大小。我尝试了以下代码:C# 如何调整多个图像的大小,c#,C#,我的任务是调整多个图像的大小。我尝试了以下代码: 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 Syste
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);
}
}
}
}
好的,那么您正在使用winforms并希望打开多个文件?还是目录?并希望调整它们的大小。但没有调整大小?还是我需要更多的咖啡?使用,我看不到在要调整大小的文件上循环 在此处阅读有关imageresizer组件的更多信息: 在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
}
}
}
两张没有一条评论的否决票:-)投票人应该在这里至少发表一条评论,以证明他们的否决票是正确的。您尝试的代码有什么问题?请注意,这个问题看起来像是“请为我编写我的程序”请求,社区不欢迎这个请求。(我还不是这个问题的反对者)。你应该像Sayse说的那样处理你的ShowDialog()(使用),也使用这个