今天要用到,操作可以像画图工具一样,图片内容等比例缩放。但是在网上找了几个等比例缩放的方法,试了发现都是有问题的,基本都是你抄他,他抄你,而且也不试试这个方法到底能不能用就瞎抄。最后自己去看Graphic类的元数据才找到解决方法。直接贴代码:
public Bitmap getnew(Image bit,double beishu)//beishu参数为放大的倍数。放大缩小都可以,0.8即为缩小至原来的0.8倍{Bitmap destBitmap = new Bitmap(Convert.ToInt32(bit.Width * beishu), Convert.ToInt32(bit.Height * beishu));Graphics g = Graphics.FromImage(destBitmap);g.Clear(Color.Transparent);//设置画布的描绘质量 positingQuality = System.positingQuality.HighQuality;g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;g.DrawImage(bit, new Rectangle(0, 0, destBitmap.Width, destBitmap.Height), 0, 0, bit.Width, bit.Height, GraphicsUnit.Pixel);g.Dispose();return destBitmap;}