我有如下所示的方法将图像保存为 jpeg。我想保存所有具有相同高度和宽度的图片而不会失真。
我怎样才能做到这一点?请帮忙
public void SaveFileOnDisk(MemoryStream ms, string FileName)
{
try
{
string appPath = HttpContext.Current.Request.ApplicationPath;
string physicalPath = HttpContext.Current.Request.MapPath(appPath);
string strpath = physicalPath + "\\Images";
string WorkingDirectory = strpath;
System.Drawing.Image imgSave = System.Drawing.Image.FromStream(ms);
Bitmap bmSave = new Bitmap(imgSave);
Bitmap bmTemp = new Bitmap(bmSave);
Graphics grSave = Graphics.FromImage(bmTemp);
grSave.DrawImage(imgSave, 0, 0, imgSave.Width, imgSave.Height);
bmTemp.Save(WorkingDirectory + "\\" + FileName + ".jpg");
imgSave.Dispose();
bmSave.Dispose();
bmTemp.Dispose();
grSave.Dispose();
}
catch (Exception ex)
{
//lblMsg.Text = "Please try again later.";
}
}