c# - 在 C# 中调整单色图像的大小

标签 c# image-resizing

我有以下代码来调整单色图像的大小(因此像素值为 0[黑色] 或 255[白色])

        Bitmap ResizedCharImage = new Bitmap(newwidth, newheight);

        using (Graphics g = Graphics.FromImage((Image)ResizedCharImage))
        {
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBilinear;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.DrawImage(CharBitmap, new Rectangle(0, 0, newwidth, newheight),
                new Rectangle(0, 0, CharBitmap.Width, CharBitmap.Height), GraphicsUnit.Pixel);
        }

我遇到的问题是,在调整大小(我正在放大图像)后,一些像素值变为 254、253、1、2 等(因此不是单色的。)我需要这不会发生.这可能吗,也许可以通过更改 Graphins 属性之一来实现?

最佳答案

使用SmoothingMode.None

关于c# - 在 C# 中调整单色图像的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2601845/

相关文章:

c# - 一个文件在 visual studio IDE 中一直打开

c# - Azure 云文件 - "The specifed resource name contains invalid characters."

c# - ASP.NET核心标识: Multiple providers for the same account

javascript - Prestashop 产品图像调整大小

c# - DrawImage 调整后的图像太小

c# - 如何从 IActionResult 检索 HTTP 代码和内容?

c# - 在等待新线程产生时调用 thread.sleep()

html - 调整不同大小的风景图像以适应带有圆框的固定肖像

javascript - 将图像大小调整为弹出窗口

asp.net - 将图像转换为流