ASP. NET generated thumbnail image

Source: Internet
Author: User
Tags bmp image

        /// <summary>        ///generate thumbnail images/// </summary>        /// <param name= "Orginalimagepat" >Original image Address</param>        /// <param name= "Thumnailpath" >thumbnail Address</param>        /// <param name= "width" >thumbnail width</param>        /// <param name= "height" >thumbnail height</param>        /// <param name= "model" >mode of generating thumbnails</param>         Public voidMakethumnail (stringOriginalimagepath,stringThumnailpath,intWidthintHeightstringmodel) {System.Drawing.Image Originalimage=System.Drawing.Image.FromFile (Originalimagepath); intThumwidth = width;//the width of the thumbnail image            intThumheight = height;//the height of the thumbnail image            intx =0; inty =0; intOriginalWidth = Originalimage.width;//the width of the original picture            intOriginalHeight = Originalimage.height;//the height of the original picture            Switch(model) { Case "HW"://Specify aspect scaling, possibly deformed                     Break;  Case "W"://specify width, height scaled by scaleThumheight = originalimage.height * Width/Originalimage.width;  Break;  Case "H"://specify height, width scaled by equal scaleThumwidth = originalimage.width * Height/Originalimage.height;  Break;  Case "Cut":                    if((Double) Originalimage.width/(Double) Originalimage.height > (Double) Thumwidth/(Double) {thumheight) {originalheight=Originalimage.height; OriginalWidth= Originalimage.height * Thumwidth/Thumheight; Y=0; X= (originalimage.width-originalwidth)/2; }                    Else{originalwidth=Originalimage.width; OriginalHeight= OriginalWidth * Height/Thumwidth; X=0; Y= (originalimage.height-originalheight)/2; }                     Break; default:                     Break; }            //Create a new BMP imageSystem.Drawing.Image bitmap =NewSystem.Drawing.Bitmap (Thumwidth, thumheight); //Create a new artboardSystem.Drawing.Graphics graphic =System.Drawing.Graphics.FromImage (bitmap); //set up a high-quality check methodGraphic. Interpolationmode =System.Drawing.Drawing2D.InterpolationMode.High; //set high quality, low speed rendering smoothnessGraphic. SmoothingMode =System.Drawing.Drawing2D.SmoothingMode.HighQuality; //Empty the canvas and fill it with a transparent background colorgraphic.            Clear (System.Drawing.Color.Transparent); //draws the specified portion of the original picture at the specified position and at the specified sizeGraphic. DrawImage (Originalimage,NewSystem.Drawing.Rectangle (0,0, Thumwidth, thumheight),NewSystem.Drawing.Rectangle (x, Y, OriginalWidth, originalheight), System.Drawing.GraphicsUnit.Pixel); Try{bitmap.            Save (Thumnailpath, System.Drawing.Imaging.ImageFormat.Jpeg); }            Catch(Exception ex) {Throwex; }            finally{originalimage.dispose (); Bitmap.                Dispose (); Graphic.            Dispose (); }        }

ASP. NET generated 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.