Tag: 绘制图像缩放

c#图像resize,同时保留宽高比

我正在尝试调整图像的大小,同时保留原始图像的宽高比,以免新图像变形。 例如: 将150 * 100图像转换为150 * 150图像。 高度的额外50个像素需要填充白色背景颜色。 这是我正在使用的当前代码。 对于resize非常有效,但是改变原始图像的纵横比可以压缩新图像。 private void resizeImage(string path, string originalFilename, int width, int height) { Image image = Image.FromFile(path + originalFilename); System.Drawing.Image thumbnail = new Bitmap(width, height); System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(thumbnail); graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; graphic.SmoothingMode = SmoothingMode.HighQuality; graphic.PixelOffsetMode = PixelOffsetMode.HighQuality; graphic.CompositingQuality = CompositingQuality.HighQuality; graphic.DrawImage(image, 0, 0, width, height); System.Drawing.Imaging.ImageCodecInfo[] […]