Using system;using system.collections.generic;using system.linq;using system.text;using System.Drawing;using System.IO; Namespace Consoleapplication3_thumbnailimg{class Program {const int HEIGHT = 190; const int WIDTH = 190; static void Main (string[] args) {string srcimgpath = @ "G:\photoes\20060725\Picture 057.jpg"; String targetfolder = @ "E:\Diary\Test\thumbnail"; Setthumbnail_1 (Srcimgpath, TargetFolder); Setthumbnail_2 (Srcimgpath, TargetFolder); Setthumbnail_3 (Srcimgpath, TargetFolder); Console.read (); } static void Setthumbnail_1 (String srcimgpath, String targetfolder) {using (Bitmap Source = NE W Bitmap (Srcimgpath)) {//return the source image if it ' s smaller than the designated thumbnail int WI, HI; WI = WIDTH; hi = HEIGHT; Maintain the aspect ratio desPite the thumbnail size parameters if (source. Width > Source. Height) {wi = WIDTH; hi = (int) (source. Height * (decimal) Width/source. Width)); } else {hi = HEIGHT; WI = (int) (source. Width * ((decimal) Height/source. Height)); } using (Image thumb = source. Getthumbnailimage (WI, Hi, null, IntPtr.Zero)) {string TargetPath = Path.Combine (targetf Older, "th_1.jpg"); Thumb. Save (TargetPath); }}}} static void Setthumbnail_2 (String srcimgpath, String targetfolder) {USI Ng (Bitmap Source = new Bitmap (Srcimgpath)) {//return the source image if it ' s smaller than th e designated thumbnail int wi, hi; WI = WIDTH; hi = HEIGHT; Maintain the aspect ratio despite the thumbnail size parameters if (source. Width > Source. Height) {wi = WIDTH; hi = (int) (source. Height * (decimal) Width/source. Width)); } else {hi = HEIGHT; WI = (int) (source. Width * ((decimal) Height/source. Height)); }//Original code that creates lousy thumbnails//System.Drawing.Image ret = source. Getthumbnailimage (Wi,hi,null,intptr.zero); using (System.Drawing.Bitmap thumb = new Bitmap (WI, HI)) {using (Graphics g = Graphics. FromImage (thumb)) {G.interpolationmode = System.Drawing.Drawing2D.Interpolation Mode.highqualitybicubic; G.fillrectangle (brushes.white, 0, 0, WI, HI); G.drawimage (Source, 0, 0, WI, HI); } String TargetPath = Path.Combine (TargetFolder, "th_2.jpg"); Thumb. Save (TargetPath); }}} static void Setthumbnail_3 (String srcimgpath, String targetfolder) {// Configure JPEG Compression Engine System.Drawing.Imaging.EncoderParameters encoderparams = new System.drawin G.imaging.encoderparameters (); long[] quality = new LONG[1]; Quality[0] = 75; System.Drawing.Imaging.EncoderParameter Encoderparam = new System.Drawing.Imaging.EncoderParameter ( System.Drawing.Imaging.Encoder.Quality, quality); Encoderparams.param[0] = Encoderparam; system.drawing.imaging.imagecodecinfo[] Arrayici = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders (); System.Drawing.Imaging.ImageCodecInfo Jpegici = null; for (int x = 0; x < arrayici.length; × x + +) { if (Arrayici[x]. Formatdescription.equals ("JPEG")) {Jpegici = arrayici[x]; Break }} using (Bitmap Source = new Bitmap (Srcimgpath)) {int WI, HI; WI = WIDTH; hi = HEIGHT; Maintain the aspect ratio despite the thumbnail size parameters if (source. Width > Source. Height) {wi = WIDTH; hi = (int) (source. Height * (decimal) Width/source. Width)); } else {hi = HEIGHT; WI = (int) (source. Width * ((decimal) Height/source. Height)); }//Original code that creates lousy thumbnails//System.Drawing.Image ret = source. Getthumbnailimage (Wi,hi,null,intptr.zero); using (System.Drawing.Bitmap thumb = new Bitmap(WI, HI)) {using (Graphics g = graphics.fromimage (thumb)) {G.interpol Ationmode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; G.fillrectangle (brushes.white, 0, 0, WI, HI); G.drawimage (source, 0, 0, WI, HI); } String TargetPath = Path.Combine (TargetFolder, "th_3.jpg"); Thumb. Save (TargetPath, Jpegici, encoderparams); } } } }}