////// 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