Upload images to generate thumbnails, the original image and thumbnail address the same time thumbnail image will be covered out
/// <summary> ///generate thumbnail images/// </summary> /// <param name= "Originalimagepath" >Source Map Path (physical path)</param> /// <param name= "Thumbnailpath" >thumbnail path (physical path)</param> /// <param name= "width" >thumbnail width</param> /// <param name= "height" >thumbnail height</param> /// <param name= "mode" >how thumbnails are generated</param> Public Static voidMakethumbnail (stringOriginalimagepath,stringThumbnailpath,intWidthintHeightstringmode) {System.Drawing.Image Originalimage=System.Drawing.Image.FromFile (Originalimagepath); //define a high-width thumbnail image intTowidth =width; intToheight =height; //defines the width of the crop intx =0; inty =0; intow =Originalimage.width; intOh =Originalimage.height; Switch(mode) { Case "HW"://Specify aspect scaling (possibly deformed) Break; Case "W"://specify wide, high proportionallyToheight = originalimage.height * Width/Originalimage.width; Break; Case "H"://specify high, wide proportionallyTowidth = originalimage.width * Height/Originalimage.height; Break; Case "Cut"://designation Aspect cut (not deformed) if((Double) Originalimage.width/(Double) Originalimage.height > (Double) Towidth/(Double) toheight) {Oh=Originalimage.height; ow= Originalimage.height * Towidth/Toheight; Y=0; X= (Originalimage.width-ow)/2; } Else{ow=Originalimage.width; Oh= originalimage.width * Height/Towidth; X=0; Y= (Originalimage.height-oh)/2; } Break; default: Break; } //Create a new BMP imageSystem.Drawing.Image bitmap =NewSystem.Drawing.Bitmap (Towidth, toheight); //Create a new artboardSystem.Drawing.Graphics g =System.Drawing.Graphics.FromImage (bitmap); //setting high-quality interpolation methodsG.interpolationmode =System.Drawing.Drawing2D.InterpolationMode.High; //set high quality, low speed rendering smoothnessG.smoothingmode =System.Drawing.Drawing2D.SmoothingMode.HighQuality; //Empty the canvas and fill it with a transparent background colorg.clear (System.Drawing.Color.Transparent); //draws the specified portion of the original picture at the specified position and at the specified sizeG.drawimage (Originalimage,NewSystem.Drawing.Rectangle (0,0, Towidth, toheight),NewSystem.Drawing.Rectangle (x, Y, Ow, OH), System.Drawing.GraphicsUnit.Pixel); Originalimage.dispose (); Try { //save thumbnails in jpg formatbitmap. Save (Thumbnailpath, System.Drawing.Imaging.ImageFormat.Jpeg); } Catch(System.Exception e) {Throwe; } finally{bitmap. Dispose (); G.dispose (); } }
Upload a picture to generate a thumbnail image