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..
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..
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;
}
using clause, not with .Dispose, as that does not ensure their disposal. The GC does not see System.Drawing instances.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.