C # generating high-definition thumbnails

Source: Internet
Author: User

////// Generate a thumbnail for the image //////Original Image path///Thumbnail width///Thumbnail height///
 Public System. drawing. image GetThumbnail (System. drawing. image image, int width, int height) {Bitmap bmp = new Bitmap (width, height); // create a System from Bitmap. drawing. graphics System. drawing. graphics gr = System. drawing. graphics. fromImage (bmp); // sets gr. smoothingMode = System. drawing. drawing2D. smoothingMode. highQuality; // The following is also set to high quality gr. compositingQuality = System. drawing. drawing2D. compositingQuality. highQuality; // set this to High gr. interpolationMode = System. drawing. drawing2D. interpolationMode. highQualityBicubic; // You can plot the original image as a System zoom-out image with the configured width and height. drawing. rectangle rectDestination = new System. drawing. rectangle (0, 0, width, height); gr. drawImage (image, rectDestination, 0, 0, image. width, image. height, GraphicsUnit. pixel); return bmp ;}

Call Method

HttpPostedFile file = photoFile. PostedFile; if (! File. contentType. contains ("image") {return "the photo format is invalid";} string ext = Path. getExtension (file. fileName ). toLower (); if (ext! = ". Jpg" & ext! = ". Gif" & ext! = ". Png" & ext! = ". Jpeg ") {return" Upload jpg, gif, and png images ";} if (file. contentLength> 5*1024*1024) {return "please upload an image within 512 bytes";} string newName = Guid. newGuid (). toString (); string tempPath = "upload/"; string img = tempPath + newName + ext; string filePath = Server. mapPath (img); if (! Directory. exists (tempPath) {Directory. createDirectory (tempPath);} using (System. drawing. image originalImage = System. drawing. image. fromStream (file. inputStream) {GetThumbnail (originalImage, 504,374 ). save (filePath );}


Zookeeper

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.