Hi,
This is very simple class that I used to generate thumbnail of images. You just pass it file name. It generate the thumbnail from file and store it in thumbnail folder. You can change width and height. And path of original image and thumbnail image. Better way is to store path in web.config file and access here.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
/// <summary>
/// Summary description for Thumbnail
/// </summary>
public class Thumbnail
{
private int Width = 100;
private int Height = 100;
string ThumbFolderPath = “~/Contents/Thumb/”;
string OriginalFolderPath = “~/Contents/Images/”;
public Thumbnail()
{
//
// TODO: Add constructor logic here
//
}
public bool GenerateThumbnail(string fileName)
{
try
{
//Get The Image From File
System.Drawing.Image OriginalImage = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(OriginalFolderPath + fileName));
//Create ITs Thumbnail
System.Drawing.Image ThumbImage = OriginalImage.GetThumbnailImage(Width, Height, null, new System.IntPtr());
//Store It in Thumbnail Folder
ThumbImage.Save(HttpContext.Current.Server.MapPath(ThumbFolderPath + fileName));
return true;
}
catch
{
return false;
}
}
}
Thanks
Rana Faisal Munir
Asp.Net Developer
Relax Solutions
Perfect!!! Thanx Rana!
Hey man, thanks for the code.
Thank you for sharing your info. I truly appreciate your efforts and I will be waiting for your further write ups thank you once again.