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

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

基本上如果我有一个图像

(White, White, White, Black) 

我希望当我放大它说6×6时,它看起来像

  (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; }