Tuesday, July 12, 2005

C# Genrerate Thumbnail Source Code

protected void genThumbnailPhoto(string fileName, string path)
{
System.IO.FileInfo info = new System.IO.FileInfo(fileName);

using(Bitmap bitmap1 = new Bitmap(fileName, false))
{
int i= 0;
int TWidth;
int THeight;
if(bitmap1.Width >= 90 && bitmap1.Height >=90 )
{
if(bitmap1.Width > bitmap1.Height )
{
TWidth = 90;
i = bitmap1.Width/90;
THeight = bitmap1.Height / i;
}
else
{
THeight = 90;
i = bitmap1.Height/90;
TWidth = bitmap1.Width / i;
}
}
else
{
TWidth = bitmap1.Width;
THeight = bitmap1.Height;

}

using(System.Drawing.Image image =
System.Drawing.Image.FromFile(fileName))
using(Bitmap bitmap = new Bitmap(image, TWidth, THeight))
{
bitmap.Save(path + "/t__" + info.Name , image.RawFormat);
}

}


}

No comments: