C #. net generates clear thumbnails,

Source: Internet
Author: User

C #. net generates clear thumbnails,

1 public void imgsize () 2 {3 // This example assumes two variables: 4 5 String src = "c:/myImages/a.jpg "; // absolute path of the source image file 6 String dest = "c:/myImages/a_th.jpg"; // the absolute path of the generated thumbnail image file 7 8 int thumbWidth = 132; // The width of the thumbnail to be generated 9 int thumbHeight = 100; // The height of the thumbnail to be generated 10 System. drawing. image image = System. drawing. image. fromFile (src); // use the Image object to load the source Image 11 12 // create a System. drawing. bitmap object, and set the width and height of the thumbnail you want. 13 int srcWidth = image. width; 14 int srcHeight = image. height; 15 Bitmap bmp = new Bitmap (thumbWidth, thumbHeight); 16 17 // create a System from Bitmap. drawing. graphics object, used to draw high-quality zoom-out graphs. 18 System. drawing. graphics gr = System. drawing. graphics. fromImage (bmp); 19 20 // set System. drawing. the SmoothingMode attribute of the Graphics object is HighQuality21 gr. smoothingMode = System. drawing. drawing2D. smoothingMode. highQuality; 22 23 // The following is also set to high quality 24 gr. compositingQuality = System. drawing. drawing2D. compositingQuality. highQuality; 25 26 // set this to High27 gr. interpolationMode = System. drawing. drawing2D. interpolationMode. high; 28 29 // draw the original image as the scaled down image with the configured width and height 30 System. drawing. rectangle rectDestination = new System. drawing. rectangle (0, 0, thumbWidth, thumbHeight); 31 gr. drawImage (image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit. pixel); 32 33 // Save the image! 34 bmp. Save (dest); 35 36 // do not forget to release the resource 37 bmp. Dispose (); 38 image. Dispose (); 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.