日期:2014-05-17 浏览次数:21216 次
图片等比缩放,不会失真,设置picturebox控件的sizemode属性为CenterImage 居中显示 public static Image GetPicBySize(Image image, int width, int height) { int picWidth = image.Width; int picHeight = image.Height; if (picWidth < width && picHeight < width) { width = picWidth; height = picHeight; } else if (picWidth / picHeight > width / height) { height = width * picHeight / picWidth; } else { width = height * picWidth / picHeight; } Bitmap thumb = new Bitmap(width, height); using (Graphics g_thumb = Graphics.FromImage(thumb)) { g_thumb.InterpolationMode = InterpolationMode.HighQualityBicubic; g_thumb.DrawImage(image, 0, 0, width, height); } return (Image)thumb; }