if (FileUploadSignature.HasFile) { string ImgExt = System.IO.Path.GetExtension(FileUploadSignature.PostedFile.FileName).ToUpper(); if (ImgExt == ".PNG" || ImgExt == ".BMP" || ImgExt == ".GIF" || ImgExt == ".JPG" || ImgExt == ".JPEG") { if (System.IO.File.Exists(Server.MapPath(@"~\Signature\" + txtEmployeeID.Value.Trim() + ".Jpeg"))) { System.IO.File.Delete(Server.MapPath(@"~\Signature\" + txtEmployeeID.Value.Trim() + ".Jpeg")); } System.Drawing.Image image = System.Drawing.Image.FromFile(FileUploadSignature.PostedFile.FileName); int thumbWidth = image.Width; if (thumbWidth > 100) { thumbWidth = 100; } else { thumbWidth = image.Width; } int srcWidth = image.Width; int srcHeight = image.Height; Decimal sizeRatio = ((Decimal)srcHeight / srcWidth); int thumbHeight = Decimal.ToInt32(sizeRatio * thumbWidth); Bitmap bmp = new Bitmap(thumbWidth, thumbHeight); System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp); gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, thumbWidth, thumbHeight); gr.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel); bmp.Save(Server.MapPath(@"~\Signature\"+txtEmployeeID.Value.Trim()+".Jpeg"), System.Drawing.Imaging.ImageFormat.Jpeg); bmp.Dispose(); ShowMessage("Saved Sucessfully"); } else { ShowMessage("Invalid Picture Format/Type"); return; } } else { ShowMessage("Please select the image then click save"); return; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)