Create a picture thumbnail method

Source: Internet
Author: User

 private void Drawimagerectrect (String rawimgpath, string newimgpath, int width, int height)       &NBS P {            System.Drawing.Image imagefrom = System.Drawing.Image.FromFile (Rawimgpath); nbsp          //source map width and height              int imagefromwidth = Imagefro m.width;            int imagefromheight = imagefrom.height;            //position in the original canvas             int X, y;           //In the original Long width             int bitmapwidth, bitmapheight;           + in canvas nbsp Calculates the actual size of the thumbnail and its position on the canvas, based on the source map and the thumbnail size to be generated              if (Imagefromwidth/width > I Magefromheight/height)             {                Bitmapwidth = (Width * imagefromheight)/height;                Bitmapheight = Imagefromheig ht;                X = (imagefromwidth-bitmapwidth)/2;      &NB Sp         Y = 0;           }            ELS e            {                Bitmapwidth = Imagefro mwidth;                Bitmapheight = (height * imagefromwidth)/width;  &NB Sp             X = 0;                Y = (Imagefromheig Ht-bitmapheight)/2;            }           //Create canvas & nbsp;            Bitmap bmp = new Bitmap (width, height);          & nbsp Graphics g = Graphics.fromimage (BMP);           //White clear            &NBS P G.clear (color.white);           //Specify a high-quality double three-time interpolation method. Perform pre-screening to ensure high-quality shrinkage. This mode produces the highest quality conversion image.              G.interpolationmode = interpolationmode.highqualitybicubic;           //Specify high-quality, low-speed rendering.              G.smoothingmode = smoothingmode.highquality;        &N Bsp  //Draws the specified portion of the specified Image at the specified position and at the specified size.              G.drawimage (Imagefrom, New Rectangle (0, 0, width, height), new Rectangle (X , Y, Bitmapwidth, bitmapheight), GraphicsUnit.Pixel);            try      &NB Sp     {               //tested. jpg format thumbnail size and quality optimization                  BMP. Save (Newimgpath, imageforMat. Jpeg);           }            catch      &NBSP ;     {           }            finally    & nbsp       {               //Show release resources          &N Bsp       Imagefrom.dispose ();                BMP. Dispose ();                g.dispose ();           }& nbsp      }


Source: http://www.cnblogs.com/tonymu/archive/2011/07/29/2121131.html;

Create a picture thumbnail method

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.