Improve the quality of thumbnails generated by ASP. NET

Source: Internet
Author: User

The thumbnails generated by ASP. NET are very distorted. If the original image file is in JPG format, you can use the following program to optimize it:

Private void makeslt (string oldimagepath, string newimagepath)
...{
// Oldimagepath-source image address newimagepath
Int width = 150; // The width of the thumbnail.
Int Height = 112; // The height of the thumbnail.
Int level = 100; // the range of the thumbnail quality from 1

System. Drawing. Image oldimage = system. Drawing. image. fromfile (oldimagepath );
System. Drawing. Image thumbnailimage = oldimage. getthumbnailimage (width, height, new system. Drawing. image. getthumbnailimageabort (thumbnailcallback), intptr. Zero );
Bitmap Bm = new Bitmap (thumbnailimage );

// Processing JPG Quality Functions
Imagecodecinfo [] codecs = imagecodecinfo. getimageencoders ();
Imagecodecinfo ICI = NULL;
Foreach (imagecodecinfo Codec in codecs)
...{
If (codec. mimetype = "image/JPEG ")
ICI = codec;
}
Encoderparameters Ep = new encoderparameters ();
Ep. Param [0] = new encoderparameter (encoder. Quality, (long) level );

BM. Save (newimagepath, ici, EP );
}

 

From http://www.chinaaspx.com/comm/dotnetbbs/Showtopic.aspx? Forum_id = 5 & id = 243972 & ppage = 2

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.