Below is code to resize the image in terms of its height and width and also its filesize.
System.Drawing.Image src_image = System.Drawing.Image.FromStreamFileUpload1.PostedFile.InputStream);
Bitmap bitmap = new Bitmap(Width,Height,System.Drawing.Imaging.PixelFormat.Format24bppRgb);
bitmap.SetResolution(src_image.HorizontalResolution, src_image.VerticalResolution);
Graphics new_g = Graphics.FromImage(bitmap);
new_g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
new_g.InterpolationMode = System.Drawing.Drawing2.InterpolationMode.HighQualityBicubic;
new_g.DrawImage(src_image, 0, 0, bitmap.Width, bitmap.Height);
src_image.Dispose();
bitmap.Save(Server.MapPath(URL) + FileUpload1.FileName.ToString(), System.Drawing.Imaging.ImageFormat.Jpeg);
bitmap.Dispose();
new_g.Dispose();
The Above Code is for Only Jpegs.
No comments:
Post a Comment