c# – 将JPEG图像调整为固定宽度,同时保持纵横比不变

如何在保持纵横比的同时将JPEG图像调整为固定宽度?以简单的方式,同时保持质量.
最佳答案
这将仅在垂直轴上缩放:

    public static Image ResizeImageFixedWidth(Image imgToResize, int width)
    {
        int sourceWidth = imgToResize.Width;
        int sourceHeight = imgToResize.Height;

        float nPercent = ((float)width / (float)sourceWidth);

        int destWidth = (int)(sourceWidth * nPercent);
        int destHeight = (int)(sourceHeight * nPercent);

        Bitmap b = new Bitmap(destWidth, destHeight);
        Graphics g = Graphics.FromImage((Image)b);
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;

        g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
        g.Dispose();

        return (Image)b;
    }

转载注明原文:c# – 将JPEG图像调整为固定宽度,同时保持纵横比不变 - 代码日志