等比例缩放图片
/// <summary>
/// 放大缩小图片尺寸
/// </summary>
/// <param name="picPath"></param>
/// <param name="reSizePicPath"></param>
/// <param name="iSize"></param>
/// <param name="format"></param>
public void PicSized(string picPath, string reSizePicPath, int iSize, ImageFormat format)
{
Bitmap originBmp = new Bitmap(picPath);
int w = originBmp.Width * iSize;
int h = originBmp.Height * iSize;
Bitmap resizedBmp = new Bitmap(w, h);
Graphics g = Graphics.FromImage(resizedBmp);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
//消除锯齿
g.SmoothingMode = SmoothingMode.AntiAlias;
g.DrawImage(originBmp, new Rectangle(0, 0, w, h), new Rectangle(0, 0, originBmp.Width, originBmp.Height), GraphicsUnit.Pixel);
resizedBmp.Save(reSizePicPath, format);
g.Dispose();
resizedBmp.Dispose();
originBmp.Dispose();
}
/// 放大缩小图片尺寸
/// </summary>
/// <param name="picPath"></param>
/// <param name="reSizePicPath"></param>
/// <param name="iSize"></param>
/// <param name="format"></param>
public void PicSized(string picPath, string reSizePicPath, int iSize, ImageFormat format)
{
Bitmap originBmp = new Bitmap(picPath);
int w = originBmp.Width * iSize;
int h = originBmp.Height * iSize;
Bitmap resizedBmp = new Bitmap(w, h);
Graphics g = Graphics.FromImage(resizedBmp);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
//消除锯齿
g.SmoothingMode = SmoothingMode.AntiAlias;
g.DrawImage(originBmp, new Rectangle(0, 0, w, h), new Rectangle(0, 0, originBmp.Width, originBmp.Height), GraphicsUnit.Pixel);
resizedBmp.Save(reSizePicPath, format);
g.Dispose();
resizedBmp.Dispose();
originBmp.Dispose();
}