2

以下两个代码示例是等效的,因为它们会生成缩放图像。也就是说,第二个会产生更高质量的缩放图像吗?我正在使用.NET 4.5。

// The short.
using(Bitmap large = new Bitmap(input, width, height))
{
    // Do whatever.
}


// The long.
using(Bitmap large = new Bitmap(width, height))
{
    using(Graphics g = Graphics.FromImage(large))
    {
        g.CompositingQuality = CompositingQuality.HighQuality;
        g.SmoothingMode = SmoothingMode.HighQuality;
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        g.PixelOffsetMode = PixelOffsetMode.HighQuality;
        g.DrawImage(input, 0, 0, width, height);
    }
    // Do whatever.
}
4

2 回答 2

2

两者的区别在于,前一个使用默认值;

CompositingQuality: Default
SmoothingMode:      None
InterpolationMode:  Bilinear
PixelOffsetMode:    Default

所以,是的,后者肯定会提高图像质量。

简化后,Bitmap 构造函数中的相关代码是(剥离了异常处理)之类的;

Graphics graphics = Graphics.FromImage((Image) this);
graphics.Clear(Color.Transparent);
graphics.DrawImage(original, 0, 0, width, height);

...这几乎就是你所拥有的,除了你正在调整质量。

于 2012-10-08T15:58:17.783 回答
0

两者之间存在细微的质量差异。第二个给出了一个稍微清晰的图像(很难看出差异 - 至少在我的测试图像中)。

我猜哪个最好是主观的,最重要的是,取决于图像的内容。

例如,较高的对比度选项可能会在减少带有叶子的树的照片时提供更好的细节,但可能会在新娘的面纱上产生波纹效果(更清晰并不总是更好)。

于 2012-10-08T15:47:25.923 回答