. Net is another method for generating thumbnails, which is not deformed and is very easy to use. net thumbnails

Source: Internet
Author: User

. Net is another method for generating thumbnails, which is not deformed and is very easy to use. net thumbnails

Generating thumbnails is a very common function. I found a method to rewrite some code, which is practical and useful.. net also generates thumbnails without deformation.

1 /// <summary> 2 /// create a thumbnail for the image. Why? 3 /// </summary> 4 /// <param name = "phyPath"> original image path of </param> 5 /// <param name = "width"> thumbnail width </param> 6 /// <param name = "height"> thumbnail height </ param> 7 // <returns> </returns> 8 public System. drawing. image GetHvtThumbnail (System. drawing. image image, int width, int height) 9 {10 // The code is 11. // For more information, see: http://hovertree.com/menu/hovertreecms/12 Bitmap m_hovertreeBmp = new Bitmap (width, height); 13 // create a System from Bitmap. drawing. graphics 14 Graphics m_HvtGr = Graphics. fromImage (m_hovertreeBmp); 15 // set 16 m_HvtGr.SmoothingMode = System. drawing. drawing2D. smoothingMode. highQuality; 17 // The following is also set to high quality 18 m_HvtGr.CompositingQuality = System. drawing. drawing2D. compositingQuality. highQuality; 19 // set this to High 20 m_HvtGr.InterpolationMode = System. drawing. drawing2D. interpolationMode. highQualityBicubic; 21 // draw the original image as the scaled down figure 22 Rectangle rectDestination = new Rectangle (0, 0, width, height); 23 24 int m_width, m_height; 25 if (image. width * height> image. height * width) 26 {27 m_height = image. height; 28 m_width = (image. height * width)/height; 29} 30 else31 {32 m_width = image. width; 33 m_height = (image. width * height)/width; 34} 35 36 m_HvtGr.DrawImage (image, rectDestination, 0, 0, m_width, m_height, GraphicsUnit. pixel); 37 38 return m_hovertreeBmp; 39}

 

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.