正好之前有写过这个,不过是用的.net自带的api写的,如果想要弄的很好的话非常难,有兴趣可以看一下插值法,有若干种办法不一一列举。
/// <summary>
/// 获取缩小后的图片
/// </summary>
/// <param name="bm">要缩小的图片</param>
/// <param name="times">要缩小的倍数</param>
/// <returns></returns>
private Bitmap GetSmall(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;
}