Find a document online ~ Share with you !!
Using the. NET method, the thumbnails generated by getthumbnailimage are severely distorted. We recommend that you generate a thumbnail without distortion.
/// <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;
}
}