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

南笙酒味 提交于 2019-12-04 03:56:49

问题


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

 (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"


回答1:


Try to set interpolation mode:

g.InterpolationMode = InterpolationMode.NearestNeighbor;



回答2:


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



回答3:


May be this could help!

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


来源:https://stackoverflow.com/questions/11456440/how-to-resize-a-bitmap-image-in-c-sharp-without-blending-or-filtering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!