- Posted by Admin on March 5, 2009
Making thubnails using C# is very easy. All you need is to make use of .Net class libraries System.Drawing, System.Drawing.Imaging and System.Drawing.Drawing2D. Here is the code that makes thumbnail of the image supplied. The original image remains untouched. New thumb file is generated.
class ImageResize
{
public static Bitmap MakeThumb(string ImagePath)
{
try
{
Image img = Image.FromFile(ImagePath);
Bitmap b = new Bitmap(img, 150, 120);
// You are use any width, height here. for now width=150, height=120 pixels
return b;
}
catch (Exception exc)
{
return (new Bitmap(1, 1));
// in case of any error, we are returning a thumbnail of 1 x 1 pixels
}
}
}
Thanks