Copy Code code as follows:
<summary>
Get thumbnails
</summary>
<returns></returns>
public bool Getthumbimg ()
{
Try
{
String Imgpath; Original path
if (Imgsourceurl. IndexOf ("\", 0) <0)//using a relative path
{
Imgpath = HttpContext.Current.Server.MapPath (Imgsourceurl); Convert to 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)//is using a relative path
{
Thumbpath=httpcontext.current.server.mappath (Thumburl);//Convert to physical path
}
Imgthumb.save (Thumbpath,imageformat.jpeg);
Imgthumb.dispose ();
return true;
}
}
Catch
{
Throw
}
}