As already mentioned, if you want all images to be the same size without distortion, you will need to resize while maintaining the aspect ratio. See this feature below:
public Image ResizeWithSameRatio(Image image, float width, float height)
{
var brush = new SolidBrush(Color.Black);
float scale = Math.Min(width / image.Width, height / image.Height);
var bmp = new Bitmap((int)width, (int)height);
var graph = Graphics.FromImage(bmp);
var scaleWidth = (int)(image.Width * scale);
var scaleHeight = (int)(image.Height * scale);
graph.FillRectangle(brush, new RectangleF(0, 0, width, height));
graph.DrawImage(image, new Rectangle(((int)width - scaleWidth)/2, ((int)height - scaleHeight)/2, scaleWidth, scaleHeight));
return bmp;
}
(, 1024x768 ):
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;
using (var original = Image.FromStream(ms))
using (var resized = ResizeWithSameRatio(original, 1024, 768))
{
resized.Save(WorkingDirectory + "\\" + FileName + ".jpg");
}
}
catch (Exception ex)
{
}
}
using Dispose().