降尺度后图像边框丢失

时间:2012-01-31 15:55:42

标签: c# image image-processing resize

当我使用Graphics类调整位图大小时,它会忽略原始图像的某些右边和底部像素。

以下是一个示例(原始版本,60x60,30x30):

original result60 result30

我的代码:

foreach(int x in new[]{60, 30})
{
    var result = new Bitmap(x, x);
    var g = Graphics.FromImage(result);
    g.DrawImage(new Bitmap(MediaDir + "original.png"), 0, 0, x, x);
    result.Save(MediaDir + "result" + x + ".png", ImageFormat.Png);
}

我错过了什么吗?

编辑,这是使用HighQualityBicubic的结果:

enter image description here enter image description here enter image description here enter image description here

3 个答案:

答案 0 :(得分:3)

将插值模式设置为InterpolationMode.HighQualityBicubic

您可以在Microsoft Tutorial中查看参数的效果。左下角的示例与您的问题类似。

答案 1 :(得分:2)

这可能是调整大小过程本身的影响。根据所使用的算法,它可能检测到边框处像素的红色不再与白色图像的整体图像相关,因此输出白色。

答案 2 :(得分:0)

我使用了这个解决方法来发现" bug"。当我调整标准eshop项目照片的大小时,有些灰色左/上边框,有些没有。所以你只需使用这段代码

g.DrawImage(src, -1, -1, width+1, height+1);

它的工作完美。我也找到了一些关于pixelmode的提示或尝试使用一些特殊的attr和drawimage方法,但它对我不起作用。

相关问题