参数times为小数则图片为放大,如times=0.5,则图片放大两倍
/// <summary> /// 按比例变化图片尺寸 /// </summary> /// <param name="bm">原图</param> /// <param name="times">变化倍数</param> /// <returns></returns> public static Bitmap ZoomPicture(Bitmap bm, double times) { int nowWidth = (int)(bm.Width / times); int nowHeight = (int)(bm.Height / times); Bitmap newbm = new Bitmap(nowWidth, nowHeight); if (times >= 1 && times <= 1.1) { newbm = bm; } else { Graphics g = Graphics.FromImage(newbm); g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.SmoothingMode = SmoothingMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality; g.DrawImage(bm, new Rectangle(0, 0, nowWidth, nowHeight), new Rectangle(0, 0, bm.Width, bm.Height), GraphicsUnit.Pixel); g.Dispose(); } return newbm; }
评论前必须登录!
注册