Public classgetthumbnailimg {/// <summary> ///read thumbnails of pictures/// </summary> /// <param name= "Picpath" >path to the source picture</param> /// <param name= "Pictemp" >Create a catalog of thumbnails</param> /// <param name= "Width" >generate the width of the thumbnail image</param> /// <param name= "Height" >generate thumbnails for high</param> /// <returns>The build succeeds to return the path, otherwise it returns ""</returns> Public Static stringGetthumbnailpic (stringPicpath,stringPictemp,intWidth,intHeight) {System.Drawing.Bitmap Bitmap=NewSystem.Drawing.Bitmap (Picpath); if(Bitmap.width >bitmap.height) {Height= Bitmap.height * Width/Bitmap.width; } Else if(Bitmap.width <bitmap.height) {Width= Bitmap.width * Height/Bitmap.height; } varimg = Bitmap.getthumbnailimage (Width, Height, () = = {return false;}, IntPtr.Zero); Try{img. Save (pictemp); returnpictemp; } Catch { return ""; } } }
Call
if(IsPostBack) {stringFileName = MapPath ("~/img/") + Guid.NewGuid (). ToString () +System.IO.Path.GetExtension (fileupload1.filename); Fileupload1.saveas (FileName); stringTempPath = Filename.replace (@"\img\",@"\img\temp\"); varPath = Getthumbnailimg.getthumbnailpic (FileName, TempPath, $, $); Image img=NewImage (); Img. IMAGEURL="~/img/temp/"+System.IO.Path.GetFileName (Path); This. Controls.Add (IMG); }
Scale pictures in equal proportion