You can try this so compress image into specific size
if (Request.Files.Count > 0)
{
HttpPostedFileBase file = Request.Files[0];
if (file != null && file.ContentLength > 0)
{
string path = Path.GetFileName(file.FileName) + ".jpeg";
string saveFilePath = Path.Combine(Server.MapPath("/Images/"), path);
if ((file.ContentLength / 1024) > 4096)
{
var newSize = new Size(100, 100);
using (var originalImage = System.Drawing.Image.FromFile(file.FileName))
{
using (var newImage = new Bitmap(newSize.Width, newSize.Height))
{
using (var canvas = Graphics.FromImage(newImage))
{
canvas.SmoothingMode = SmoothingMode.AntiAlias;
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
canvas.PixelOffsetMode = PixelOffsetMode.HighQuality;
canvas.DrawImage(originalImage, new System.Drawing.Rectangle(new Point(0, 0), newSize));
newImage.Save(saveFilePath, originalImage.RawFormat);
}
}
}
}
else
{
file.SaveAs(saveFilePath);
}
}
}