user1986324
user1986324

Reputation: 11

Image Resize in ASP.NET C#

I want resize one image into Multiple Images like thumb_image,Small_image,big_image on One Button click in ASP.NET C#.

Please provide me help or sample code for the same..

Upvotes: 1

Views: 1974

Answers (2)

Lilith River
Lilith River

Reputation: 16468

I hope you use a library to do this. There are a lots of code samples, but they're not designed for server side use, whereas ImageResizer is.

At least read this article on what pitfalls to avoid if you decide to go copy & paste route.

Upvotes: 0

Muhammed Irshad
Muhammed Irshad

Reputation: 92

You could do something like this.

 var thumbNail = CreateThumbnail(100, 100, fullPath);

        public static Image CreateThumbnail(int maxWidth, int maxHeight, string path)
    {

        var image = Image.FromFile(path);
        var ratioX = (double)maxWidth / image.Width;
        var ratioY = (double)maxHeight / image.Height;
        var ratio = Math.Min(ratioX, ratioY);
        var newWidth = (int)(image.Width * ratio);
        var newHeight = (int)(image.Height * ratio);
        var newImage = new Bitmap(newWidth, newHeight);
        Graphics.FromImage(newImage).DrawImage(image, 0, 0, newWidth, newHeight);
        image.Dispose();
        return newImage;
    }

Upvotes: 1

Related Questions