public void imgsize() { //本例中假定了兩個變量: String src = "c:/myImages/a.jpg"; //源圖像文件的絕對路徑 String dest = "c:/myImages/a_th.jpg"; //生成的縮略圖圖像文件的絕對路徑 int thumbWidth = 132; //要生成的縮略圖的寬度 int thumbHeight = 100; //要生成的縮略圖的高度 System.Drawing.Image image = System.Drawing.Image.FromFile(src); //利用Image對象裝載源圖像 //接著創建一個System.Drawing.Bitmap對象,並設置你希望的縮略圖的寬度和高度。 int srcWidth = image.Width; int srcHeight = image.Height; Bitmap bmp = new Bitmap(thumbWidth, thumbHeight); //從Bitmap創建一個System.Drawing.Graphics對象,用來繪制高質量的縮小圖。 System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp); //設置 System.Drawing.Graphics對象的SmoothingMode屬性為HighQuality gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //下面這個也設成高質量 gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; //下面這個設成High gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //把原始圖像繪制成上面所設置寬高的縮小圖 System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, thumbWidth, thumbHeight); gr.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel); //保存圖像,大功告成! bmp.Save(dest); //最後別忘了釋放資源 bmp.Dispose(); image.Dispose(); }