C # Generate thumbnails of non-distorted methods instance sharing
<summary>///get thumbnail///</summary>///<returns></returns> public bool Getthumbimg () {try{ String Imgpath; The original path if (Imgsourceurl. IndexOf ("\", 0) <0)//Use relative path {Imgpath = HttpContext.Current.Server.MapPath (Imgsourceurl);//Convert to physical path}else{imgpa Th=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)//Use relative path {thumbpath=httpcontext.current.server.mappath (thumburl);//Convert to physical path}imgthumb.save ( THUMBPATH,IMAGEFORMAT.JPEG); Imgthumb.dispose (); return true;}} Catch{throw;}}
The above is the C # generated thumbnail image of the method instance sharing content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!