图像质量不好

时间:2011-09-13 07:47:45

标签: c# .net gdi+

问题:

我几天前在这里发现了这个功能,但我再也找不到了。它调整图像大小,但输出质量不好。看起来颜色深度是8位。

第一张照片是原始照片,第二张照片是Photoshop,最后一张是通过代码调整大小:

样品:

Resize samples

功能:

Image ResizeImage(Image original, int targetWidth)
{
    double percent = (double)original.Width / targetWidth;
    int destWidth = (int)(original.Width / percent);
    int destHeight = (int)(original.Height / percent);

    Bitmap b = new Bitmap(destWidth, destHeight);
    Graphics g = Graphics.FromImage((Image)b);
    try
    {

        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        g.SmoothingMode = SmoothingMode.HighQuality;
        g.PixelOffsetMode = PixelOffsetMode.HighQuality;
        g.CompositingQuality = CompositingQuality.HighQuality;

        g.DrawImage(original, 0, 0, destWidth, destHeight);
    }
    finally
    {
        g.Dispose();
    }

    return (Image)b;
}

1 个答案:

答案 0 :(得分:1)

在某个阶段看起来像图像被转换为​​索引颜色像素格式。检查this article并尝试明确设置PixelFormatResolution属性。