Friday, 27 May 2011

Change image size in asp.net with C#.

System.Drawing.Image image = System.Drawing.Image.FromFile(url+"/"+filename);
            int srcWidth = image.Width;
            int thumbWidth;
            int srcHeight = image.Height;
            int thumbHeight = 440;
            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);
            string newfilename = filename.Substring(0, filename.LastIndexOf('.'))+reference;
            string fileExt=filename.Substring(filename.LastIndexOf('.'));
            bmp.Save(url + "\\" + newfilename + fileExt);
            bmp.Dispose();           
            image.Dispose();
         

No comments:

Post a Comment

Table Partitioning in SQL Server

  Table Partitioning in SQL Server – Step by Step Partitioning in SQL Server task is divided into four steps: Create a File Group Add Files ...