1PublicvoidImgsize ()2{3//In this example, two variables are assumed:45 String src ="C:/myimages/a.jpg";//Absolute path to the source image file6 String dest ="C:/myimages/a_th.jpg";//The absolute path of the generated thumbnail image file78int thumbwidth =132;//The width of the thumbnail to be generated9int thumbheight =100;//The height of the thumbnail to be generatedTen System.Drawing.Image Image = System.Drawing.Image.FromFile (src);//To load a source image with an image object1112//Then create a System.Drawing.Bitmap object and set the width and height of the thumbnail you want.13int srcwidth =Image. Width;14int srcheight =Image. Height;Bitmap BMP =NewBitmap (Thumbwidth, thumbheight);1617//Create a System.Drawing.Graphics object from bitmap to draw a high-quality zoomed-out diagram.System.Drawing.Graphics gr =System.Drawing.Graphics.FromImage (BMP);1920//Set the SmoothingMode property of the System.Drawing.Graphics object to highqualityGr. SmoothingMode =System.Drawing.Drawing2D.SmoothingMode.HighQuality;2223//The following one is also set to high qualityGr.compositingquality =System.Drawing.Drawing2D.CompositingQuality.HighQuality;2526//The following is set to highGr. Interpolationmode =System.Drawing.Drawing2D.InterpolationMode.High;2829//Draw the original image into a zoomed-out diagram above the set widthSystem.Drawing.Rectangle rectdestination =New System.Drawing.Rectangle (0,031 Gr. DrawImage (image, Rectdestination, 0, Srcwidth, Srcheight, GraphicsUnit.Pixel); 32 33 // Save the image and you are done! 34 BMP. Save (dest); 35 36 //37 BMP. Dispose (); 38 image. Dispose (); 39}
C#.net generate a crisp thumbnail image