con*_*att 2 c# resize image image-resizing
我需要一个非常简单的c#图像缩放器.简单来说,我的意思很简单.这只是一个循环遍历单个目录并将该目录中的所有图片更改为相同分辨率的程序.这是我到目前为止所拥有的.
private void Form1_Load(object sender, EventArgs e)
{
string[] files = null;
int count = 0;
files = System.IO.Directory.GetFiles(@"C:\Users\..\..\ChristmasPicsResized");
foreach (string file in files)
{
System.Drawing.Bitmap bmp = System.Drawing.Bipmap.FromFile(file);
ResizeBitmap(bmp, 807, 605);
bmp.Save(file);
count++;
lblCount.Text = count.ToString();
}
}
public Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
{
Bitmap result = new Bitmap(nWidth, nHeight);
using (Graphics g = Graphics.FromImage((Image)result))
g.DrawImage(b, 0, 0, nWidth, nHeight);
return result;
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是图片在打开时无法保存.我不确定如何将其变成文件流.什么应该是一个非常简单的应用程序对我来说似乎并不那么简单.有什么帮助吗?