How to resize image in .NET or ASP.NET?

public static System.Drawing.Image ResizeImage(System.Drawing.Image sourceImage, int width, int height)


    System.Drawing.Image oThumbNail = new Bitmap(sourceImage, width, height);

    Graphics oGraphic = Graphics.FromImage(oThumbNail);

    oGraphic.CompositingQuality = CompositingQuality.HighQuality;

    oGraphic.SmoothingMode = SmoothingMode.HighQuality;

    oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic;

    Rectangle oRectangle = new Rectangle(0, 0, width, height);

    oGraphic.DrawImage(sourceImage, oRectangle);

    return oThumbNail;


Posted on Wednesday, March 19, 2008 by | Comments (2) | Add Comment



Re:How to resize image in .NET or ASP.NET?

how we use it. if i send value in function then source image has problem

Posted on 5/20/2009 10:05:10 AM by enam #

You can save it:


or use it as described here:


Re:How to resize image in .NET or ASP.NET?

This article lists the pitfalls of using the above approach:

Using this as-is in an app will crash the server.

It's best to use a library for image processing that handles memory management properly and supports various image formats.

There is a free and open-source module for doing just that:

Posted on 4/26/2011 1:36:26 PM by Nathanael Jones #

Nice catch.

New Comment

Your Name:
Email (for internal use only):
Code above:


Valid HTML5