private Bitmap Resize_Image(Stream streamImage, int maxWidth, int maxHeight) { Bitmap originalImage = new Bitmap(streamImage); int newWidth = originalImage.Width; int newHeight = originalImage.Height; if (originalImage.Width > maxWidth) { newWidth = maxWidth; } if (originalImage.Height > maxHeight) { newHeight = maxHeight; } return new Bitmap(originalImage, newWidth, newHeight); } protected void btnUpload_Click(object sender, EventArgs e) { if (imgUpload.HasFile) { //string img = string.Empty; Bitmap bmpImg = null; try { //int fileSize = imgUpload.PostedFile.ContentLength; // int maxFileSize = 150; // if (maxFileSize > fileSize) // { // maxFileSize = fileSize; // } // else // { // maxFileSize = fileSize; // } bmpImg = Resize_Image(imgUpload.PostedFile.InputStream, 380, 380); string fileName = imgUpload.PostedFile.FileName; string saveLocation = Server.MapPath("UploadImages/" + fileName); bmpImg.Save(saveLocation); } catch (Exception ex) { Response.Write("Error occured: " + ex.Message.ToString()); } finally { img = string.Empty; bmpImg.Dispose(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)