【问题标题】:Resize a bitmap like MS Paint - no antialiasing像 MS Paint 一样调整位图大小 - 无抗锯齿
【发布时间】:2021-10-01 06:45:58
【问题描述】:

当我使用这种方法调整位图大小时:

    private Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
    {
        Bitmap result = new Bitmap(nWidth, nHeight);
        using (Graphics g = Graphics.FromImage((Image)result))
        {
            g.SmoothingMode = SmoothingMode.None;
            g.DrawImage(b, 0, 0, nWidth, nHeight);
        }
        return result;
    }

即使我指定了它仍然使用抗锯齿:

g.SmoothingMode = SmoothingMode.None;

我只想要基本的大小调整,没有任何平滑。

【问题讨论】:

    标签: c# visual-studio-2010


    【解决方案1】:

    而不是做

    g.SmoothingMode = SmoothingMode.None;
    

    你应该这样做

    g.InterpolationMode = InterpolationMode.NearestNeighbor;
    

    【讨论】:

    • 通常不够,更改 PixelOffsetMode 为好,使用 Half。
    【解决方案2】:

    抗锯齿是亚像素的事情,你实际上是在调整大小操作期间寻找Nearest Neighbourinterpolation

    【讨论】:

      【解决方案3】:

      查看InterpolationMode 属性。

      我想这就是你想要的。 Hanselman 有一篇很好的博客文章。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多