Upload a picture to generate a thumbnail image

Source: Internet
Author: User
Tags bmp image

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.