You can resize the image before saving it , if you are using the fileupload then this code will help you to resize the image with no effect on the picture quality and you can save it in any format such as .png ,.jpeg, .bmp and .gif etc.
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
fileupload1.SaveAs(Server.MapPath("images/tempImage/" + fileupload1.FileName));
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("images/tempImage/" + fileupload1.FileName));
int newwidthimg = 200;
float AspectRatio = (float)image.Size.Width / (float)image.Size.Height;
int newHeight = 200;
Bitmap bitMAP1 = new Bitmap(newwidthimg, newHeight);
Graphics imgGraph = Graphics.FromImage(bitMAP1);

Rahul KumarPosted Aug 7, 2020, 2:24 AM
I am Getting Error imgQuality, SmoothingMode,InterpolationMode,DrawImageimageRectangle all are not found.
Akhil KumarPosted Feb 9, 2017, 8:17 AM
Protected void Button1_Click(object sender, EventArgs e) { string filename = Path.GetFileName(FileUpload1.FileName); FileUpload1.SaveAs(Server.MapPath("Images20/" + filename)); string path = "D:\\Backup 16 sep 2016\\Image-resized\\Images20\\" + filename; System.Drawing.Image NewImage = CreateThumbnails(20, 20, path); NewImage.Save(path, ImageFormat.Jpeg); } public System.Drawing.Image CreateThumbnails(int maxWidth, int maxHeight, string path) { var image = System.Drawing.Image.FromFile(path); var newWidth = maxWidth; var newHeight = maxHeight; var newImage = new Bitmap(newWidth, newHeight); Graphics thumbGraph = Graphics.FromImage(newImage); thumbGraph.CompositingQuality = CompositingQuality.HighQuality; thumbGraph.SmoothingMode = SmoothingMode.HighQuality; thumbGraph.SmoothingMode = SmoothingMode.HighQuality; //thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic; thumbGraph.DrawImage(image, 0, 0, newWidth, newHeight); image.Dispose(); return newImage; }
Sadik JamaniPosted Sep 10, 2015, 9:25 AM
I am Getting Error imgQuality, SmoothingMode,InterpolationMode,DrawImageimageRectangle all are not found
Bhupendra SinghPosted Jul 15, 2014, 7:21 AM
public string CreateThumbnail(int maxWidth, int maxHeight, string path) { var image = System.Drawing.Image.FromFile(path); var ratioX = (double)maxWidth / image.Width; var ratioY = (double)maxHeight / image.Height; var ratio = Math.Min(ratioX, ratioY); var newWidth = (int)(image.Width * ratio); var newHeight = (int)(image.Height * ratio); var newImage = new Bitmap(newWidth, newHeight); Graphics thumbGraph = Graphics.FromImage(newImage); thumbGraph.CompositingQuality = CompositingQuality.HighQuality; thumbGraph.SmoothingMode = SmoothingMode.HighQuality; //thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic; thumbGraph.DrawImage(image, 0, 0, newWidth, newHeight); image.Dispose(); string fileRelativePath = "newsizeimages/" + maxWidth + Path.GetFileName(path); newImage.Save(Server.MapPath(fileRelativePath), newImage.RawFormat); return fileRelativePath; } http://bhupendrasinghsaini.blogspot.in/2014/07/resize-image-in-c.html
Sheela K RPosted Jul 7, 2014, 2:45 AM
Thank you it works for me
sheela k rPosted Jul 2, 2014, 2:27 AM
I am Getting Error for thumbnailGraph. What is this thumbnailGraphin this article