Thursday, March 8, 2012

How to Resize Image programaticaly in C#

Following is the function to resize the image, give the image, width and height to this function it will return the resized image....
private static Image resizeImage(Image imgToResize, int x, int y)
        {
            int destWidth = x;
            int destHeight = y;

            Bitmap b = new Bitmap(destWidth, destHeight);
            Graphics g = Graphics.FromImage((Image)b);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
            g.Dispose();

            return (Image)b;
        }

No comments:

Post a Comment