Copy codeThe Code is as follows:
/// <Summary>
/// Obtain the thumbnail
/// </Summary>
/// <Returns> </returns>
Public bool GetThumbImg ()
{
Try
{
String imgpath; // original path
If (imgsourceurl. IndexOf ("\", 0) <0) // The relative path is used.
{
Imgpath = HttpContext. Current. Server. MapPath (imgsourceurl); // convert it to a physical path
}
Else
{
Imgpath = imgsourceurl;
}
System. Drawing. Image sourceImage = System. Drawing. Image. FromFile (imgpath );
Int width = sourceImage. Width;
Int height = sourceImage. Height;
If (thumbwidth <= 0)
{
Thumbwidth = 120;
}
If (thumbwidth> = width)
{
Return false;
}
Else
{
(Thumbwidth, thHeight * thumbwidth/thWidth, null, IntPtr. Zero );
Image imgThumb = new System. Drawing. Bitmap (thumbwidth, height * thumbwidth/width );
System. Drawing. Graphics g = System. Drawing. Graphics. FromImage (imgThumb );
G. InterpolationMode = System. Drawing. Drawing2D. InterpolationMode. HighQualityBicubic;
G. DrawImage (sourceImage, new Rectangle (0, 0, thumbwidth, height * thumbwidth/width), 0, 0, width, height, GraphicsUnit. Pixel );
String thumbpath = "";
SourceImage. Dispose ();
If (thumburl = "")
{
Thumbpath = imgpath;
}
If (thumbpath. IndexOf ("\", 0) <0) // The relative path is used.
{
Thumbpath = HttpContext. Current. Server. MapPath (thumburl); // convert it to a physical path
}
ImgThumb. Save (thumbpath, ImageFormat. Jpeg );
ImgThumb. Dispose ();
Return true;
}
}
Catch
{
Throw;
}
}