繁体   English   中英

如何在没有混合或过滤的情况下在C#中调整位图图像的大小?

[英]How to resize a bitmap image in C# without blending or filtering?

我有一个灰度图像,我想放大,以便我可以更好地看到单个像素。 我已经尝试将平滑模式设置为无和一些不同的插值模式(如此处的其他问题所示),但图像仍然在我看来,好像它们在显示在屏幕上之前仍在进行某种混合。

基本上如果我有一个图像

(White, White,
 White, Black)

我希望当我把它扩大到说6x6时,它看起来像

 (White, White, White, White, White, White
  White, White, White, White, White, White
  White, White, White, White, White, White
  White, White, White, Black, Black, Black
  White, White, White, Black, Black, Black
  White, White, White, Black, Black, Black)

黑色和白色区域之间没有褪色,应该看起来像一个正方形。 图像应该看起来更“像素化”而不是“模糊”

尝试设置插值模式:

g.InterpolationMode = InterpolationMode.NearestNeighbor;

我也想做类似的事情。 当我发现这个问题时,我所寻找的答案都不是完全正确的。 这就是让我到达我想成为的地方,以及从你的问题中我能说出你想要的东西。

private Bitmap ResizeBitmap(Bitmap sourceBMP, int width, int height)
{
    Bitmap result = new Bitmap(width, height);
    using (Graphics g = Graphics.FromImage(result))
    {
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
        g.DrawImage(sourceBMP, 0, 0, width, height);
    }
    return result;
}

可能这可能会有所帮助!

http://www.codeproject.com/Articles/191424/Resizing-an-Image-On-The-Fly-using-NET

另外,请您实施此方法,看看它是否适合您?

private static Bitmap ResizeBitmap(Bitmap sourceBMP, int width, int height )
{
            Bitmap result = new Bitmap(width, height);
            using (Graphics g = Graphics.FromImage(result))
                g.DrawImage(sourceBMP, 0, 0, width, height);
            return result;
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM