Resize image while uploading image

Namespace required:
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
— .cs page coding on Save button—————–
// Create a new bitmap which will hold the previous resized bitmap
Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
// Create a graphic based on the new bitmap
Graphics oGraphics = Graphics.FromImage(newBMP);

// Set the properties for the new graphic file
oGraphics.SmoothingMode = SmoothingMode.AntiAlias; oGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
// Draw the new graphic based on the resized bitmap
oGraphics.DrawImage(originalBMP, 0, 0, newWidth, newHeight);

// Save the new graphic file to the server
newBMP.Save(Server.MapPath(“~/StaffImages/” + StaffId + Path.GetExtension(fupImage.FileName)));

// Once finished with the bitmap objects, we deallocate them.
originalBMP.Dispose();
newBMP.Dispose();
oGraphics.Dispose();

Share