/// <summary> /// 压缩图函数 /// </summary> /// <param name="fileCreateUrl">原始图片路径</param> /// <param name="fileSaveUrl">压缩图片路径</param> public static void MakeSmallImg(String fileCreateUrl, string fileSaveUrl) { //根据路径获取图片流 System.Drawing.Image myImage = System.Drawing.Image.FromFile(fileCreateUrl, true); //取得图片大小 System.Drawing.Size mySize = new Size((int)myImage.Width, (int)myImage.Height); //新建一个bmp图片 System.Drawing.Image bitmap = new System.Drawing.Bitmap(mySize.Width, mySize.Height); //新建一个画板 System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //设置高质量插值法 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //清空一下画布 g.Clear(Color.White); //在指定位置画图 g.DrawImage(myImage, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), new System.Drawing.Rectangle(0, 0, myImage.Width, myImage.Height), System.Drawing.GraphicsUnit.Pixel); //保存缩略图 bitmap.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg); g.Dispose(); myImage.Dispose(); bitmap.Dispose(); }