C# 调整大小给我带来沉重的形象

C# 调整大小给我带来沉重的形象,c#,drawing,C#,Drawing,我正在通过以下方法调整jpeg 1200x900,556kb的大小: public static Image ResizeImage(Image imgToResize, int height) //height=400 { int destWidth; int destHeight; int sourceWidth = imgToResize.Width; int sourceHeight = imgToResize.Height; float nP

我正在通过以下方法调整jpeg 1200x900,556kb的大小:

public static Image ResizeImage(Image imgToResize, int height) //height=400
{
    int destWidth;
    int destHeight;

    int sourceWidth = imgToResize.Width;
    int sourceHeight = imgToResize.Height;

    float nPercent = 0;

    float nPercentH = 0;


    nPercentH = ((float)height / (float)sourceHeight);


    nPercent = nPercentH;


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

    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 b;
}
拯救

Image image = Image.FromStream(new FileStream(path, FileMode.Open));
Image imageAfterResizing =ResizeImage(image,400);
imageAfterResizing.Save(@"c:\myPhoto.jpg");
给我555kb 533x400 jpeg

为什么这张照片这么重

用于照片jpeg 2111kb 2156x1571 我得到556kb 533x400 jpeg

为什么在第一种情况下是如此可怕

  • 您确定它是JPEG格式,而不是其他具有JPEG文件扩展名的文件格式吗
  • 将JPEG质量设置为较低

JPEG图像的压缩是在保存时决定的,而您显示的代码中不包括该压缩


默认的压缩级别非常低,因此您可以将其设置为在保存图像时对图像进行更多的压缩。

我想您会发现,在这两种情况下,您都将较大的JPEG图像转换为位图图像

两个位图都是533x400像素,并且都具有大致相同的文件大小556kb


如果要调整文件大小,则需要使用与位图图像不同的格式。

看起来您没有指定保存格式,它可能会以位图的形式出现在另一端


指定保存期间的格式:img.save(“C:\\foo.jpg”,ImageFormat.Jpeg)

你能展示一些示例图像吗?创建图像时使用什么JPEG质量?如何保存图像?AFAIK默认情况下保存为BMP