设置图片的长宽
用插值算法
之前写过一个缩小的,放大也是一样的,供楼主参考。
///
/// 获取缩小后的图片
///
/// 要缩小的图片
/// 要缩小的倍数
///
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;
}
Picturebox控件大小不变,只改变图片大小吗?