1

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..

3
  • Have you tried anything yet? Commented Feb 22, 2013 at 6:38
  • If you google the same you will get may links. Have you tried one of them? Commented Feb 22, 2013 at 6:43
  • yes @Andrew Barber I tried one but it not working Commented Feb 22, 2013 at 7:16

2 Answers 2

1

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;
    }
Sign up to request clarification or add additional context in comments.

1 Comment

All System.Drawing objects must be disposed with a using clause, not with .Dispose, as that does not ensure their disposal. The GC does not see System.Drawing instances.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.