mg = image
newsize = height and width
Call the Resize function using the following code
Bitmap mg = new Bitmap(strUploadPath); Size newSize = new Size(Convert.ToInt32(DispMaxWidth), Convert.ToInt32(DispMaxHeight)); Bitmap bp = ResizeImage(mg, newSize); if (bp != null) bp.Save(strUploadPath, System.Drawing.Imaging.ImageFormat.Jpeg); private Bitmap ResizeImage(Bitmap mg, Size newSize) { double ratio = 0d; double myThumbWidth = 0d; double myThumbHeight = 0d; int x = 0; int y = 0; Bitmap bp; if ((mg.Width / Convert.ToDouble(newSize.Width)) > (mg.Height / Convert.ToDouble(newSize.Height))) ratio = Convert.ToDouble(mg.Width) / Convert.ToDouble(newSize.Width); else ratio = Convert.ToDouble(mg.Height) / Convert.ToDouble(newSize.Height); myThumbHeight = Math.Ceiling(mg.Height / ratio); myThumbWidth = Math.Ceiling(mg.Width / ratio);
source share