/// <Summary>
/// Generate a thumbnail
/// </Summary>
/// <Param name = "sourceimagepath"> original image path (absolute path) </param>
/// <Param name = "thumbnailimagewidth"> width of the thumbnail (the height is automatically generated based on the proportion of the source image) </param>
Public Image tothumbnailimages (string sourceimagepath, int thumbnailimagewidth)
{
Image retimage = NULL;
String sourceimagepath = sourceimagepath;
Int thumbnailimagewidth = thumbnailimagewidth;
String sext = sourceimagepath. substring (sourceimagepath. lastindexof ("."). tolower ();
// Create an image object from the original image
Stream FS = new filestream (sourceimagepath, filemode. Open );
System. Drawing. Image image = system. Drawing. image. fromstream (FS );
FS. Close ();
// System. Drawing. Image image = system. Drawing. image. fromfile (sourceimagepath );
Int num = (thumbnailimagewidth/4) * 3 );
Int width = image. width;
Int Height = image. height;
// Calculate the image proportion
If (double) width)/(double) height)> = 1.33333333333333f)
{
Num = (height * thumbnailimagewidth)/width );
}
Else
{
Thumbnailimagewidth = (width * num)/height );
}
If (thumbnailimagewidth <1) | (Num <1 ))
{
Return retimage;
}
// Initialize a new bitmap instance with the specified size and format
Bitmap bitmap = new Bitmap (thumbnailimagewidth, num, pixelformat. format32bppargb );
// Create a new graphics object from the specified image object
Graphics graphics = graphics. fromimage (Bitmap );
// Clear the entire drawing surface and fill it with a transparent background color
Graphics. Clear (color. Transparent );
// Draw the original image object at the specified position and by the specified size
Graphics. drawimage (image, new rectangle (0, 0, thumbnailimagewidth, num ));
Retimage = image. Clone () as image;
Image. Dispose ();
Bitmap. Dispose ();
Graphics. Dispose ();
Return retimage;
}