C # ASP. NET scale-down code (Basic edition)

Source: Internet
Author: User

I'm not going to say much.

if(request.files["file1"] ==NULL) {Response.Write ("<script>alert (\ "Please select Upload file!\") </script>"); }        Else        {            //Get Picture Format            stringFileExtension = Path.getextension (request.files["file1"].            FileName); if(FileExtension = =". jpg")            {                //Picture Save Path                stringSavepath = Server.MapPath (@"~/uploadpic/"); //take the picture streamStream Sam = request.files["file1"].                InputStream; //take the picture stream and save the image .System.Drawing.Image im =System.Drawing.Image.FromStream (SAM); //Original Width                intOwidth =im.                Width; //Original Height                intOheight =im.                Height; //set thumbnail initial width                intTwidth = About; //set thumbnail initial height                intTheight = the; //create an empty BMP pictureBitmap BT =NewBitmap ( About, the); //calculates the width and height of the thumbnail proportionally                if(Owidth >=oheight) Theight= (int) Math.floor (convert.todouble (oheight) * (convert.todouble (twidth)/convert.todouble (owidth)); ElseTwidth= (int) Math.floor (convert.todouble (owidth) * (convert.todouble (theight)/convert.todouble (oheight)); //Center Picture                intPWidth = ( About-Twidth)/2; intPheight = ( the-Theight)/2; //create an instance of a drawing pictureGraphics g =Graphics.fromimage (BT); //Control picture qualityG.interpolationmode =System.Drawing.Drawing2D.InterpolationMode.Low; //control anti-aliasingG.smoothingmode =System.Drawing.Drawing2D.SmoothingMode.HighQuality; //Set Transparent Backgroundg.clear (color.transparent); //generate thumbnail imagesG.drawimage (IM,NewRectangle (PWidth, Pheight, Twidth, Theight),NewRectangle (0,0, Owidth, oheight), GraphicsUnit.Pixel); //Save PictureBt. Save (string. Format ("{0}{1}.png", Savepath, DateTime.Now.ToString ("yyyymmddhhmmss_yyyy") ), imageformat.png); }            Else{Response.Write ("<script>alert (\ "Picture format is incorrect!\") </script>"); }        }

Reprint Please specify!

C # ASP. NET scale-down code (Basic edition)

Related Article

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.