简体   繁体   English

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

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

I have a gray scale image that I would like to enlarge so that I can better see the individual pixels. 我有一个灰度图像,我想放大,以便我可以更好地看到单个像素。 I've tried setting Smoothing mode to none and some different Interpolation Modes (as suggested on other questions on here), but the images still appear to me as if they are still doing some sort of blending before being displayed on the screen. 我已经尝试将平滑模式设置为无和一些不同的插值模式(如此处的其他问题所示),但图像仍然在我看来,好像它们在显示在屏幕上之前仍在进行某种混合。

basically If I have a image that is 基本上如果我有一个图像

(White, White,
 White, Black)

I want when I enlarge it to say 6x6, it to look like 我希望当我把它扩大到说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)

With no fading between the black and white areas, should look like a square. 黑色和白色区域之间没有褪色,应该看起来像一个正方形。 The image should look more "pixelized" rather then "Blurry" 图像应该看起来更“像素化”而不是“模糊”

尝试设置插值模式:

g.InterpolationMode = InterpolationMode.NearestNeighbor;

I too was looking to do something similar. 我也想做类似的事情。 When I found this question neither answer were quite what I was looking for but combined they were. 当我发现这个问题时,我所寻找的答案都不是完全正确的。 This is what got me to where I wanted to be and from what I can tell from your question what you want. 这就是让我到达我想成为的地方,以及从你的问题中我能说出你想要的东西。

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

May be this could help! 可能这可能会有所帮助!

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

Else can you please implement this method and see whether it works for you? 另外,请您实施此方法,看看它是否适合您?

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